File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,17 @@ export async function runWebSearch(
48
48
webSearch . results =
49
49
( results . organic_results &&
50
50
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
+ }
54
59
} ) ) ??
55
60
[ ] ;
61
+ webSearch . results = webSearch . results . filter ( ( value ) => value !== null ) ;
56
62
webSearch . results = webSearch . results
57
63
. filter ( ( { link } ) => ! DOMAIN_BLOCKLIST . some ( ( el ) => link . includes ( el ) ) ) // filter out blocklist links
58
64
. slice ( 0 , MAX_N_PAGES_SCRAPE ) ; // limit to first 10 links only
You can’t perform that action at this time.
0 commit comments