Skip to content

Commit e63c1d7

Browse files
muhammadbaqirjafarimuhammadbaqir1327nsarrazin
authored
Fixes "invalid url" error in websearch (#675)
* Fixed #656 * lint --------- Co-authored-by: muhammadbaqir1327 <muhammad.baqir@arbisoft.com> Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent f09c5f3 commit e63c1d7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/lib/server/websearch/runWebSearch.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ export async function runWebSearch(
4848
webSearch.results =
4949
(results.organic_results &&
5050
results.organic_results.map((el: { title?: string; link: string; text?: string }) => {
51-
const { title, link, text } = el;
52-
const { hostname } = new URL(link);
53-
return { title, link, hostname, text };
51+
try {
52+
const { title, link, text } = el;
53+
const { hostname } = new URL(link);
54+
return { title, link, hostname, text };
55+
} catch (e) {
56+
// Ignore Errors
57+
return null;
58+
}
5459
})) ??
5560
[];
61+
webSearch.results = webSearch.results.filter((value) => value !== null);
5662
webSearch.results = webSearch.results
5763
.filter(({ link }) => !DOMAIN_BLOCKLIST.some((el) => link.includes(el))) // filter out blocklist links
5864
.slice(0, MAX_N_PAGES_SCRAPE); // limit to first 10 links only

0 commit comments

Comments
 (0)