From ad1a6fbc74eeb51c8ac2be870c4535382c8e0428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Tue, 10 Sep 2024 19:41:01 +0200 Subject: [PATCH] fix(v1/map): handle invalid URLs gracefully --- apps/api/src/controllers/v1/map.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/api/src/controllers/v1/map.ts b/apps/api/src/controllers/v1/map.ts index e6abd9ae..a9c61d04 100644 --- a/apps/api/src/controllers/v1/map.ts +++ b/apps/api/src/controllers/v1/map.ts @@ -88,7 +88,13 @@ export async function mapController( links = performCosineSimilarity(links, searchQuery); } - links = links.map((x) => checkAndUpdateURLForMap(x).url.trim()); + links = links.map((x) => { + try { + return checkAndUpdateURLForMap(x).url.trim() + } catch (_) { + return null; + } + }).filter(x => x !== null); // allows for subdomains to be included links = links.filter((x) => isSameDomain(x, req.body.url));