@@ -33,39 +33,40 @@ export async function getUrlContextItems(
3333 query : string ,
3434 fetchFn : FetchFunction ,
3535) : Promise < ContextItem [ ] > {
36- try {
37- const url = new URL ( query ) ;
38- const icon = await fetchFavicon ( url ) ;
39- const resp = await fetchFn ( url ) ;
40- const html = await resp . text ( ) ;
36+ const url = new URL ( query ) ;
37+ const icon = await fetchFavicon ( url ) ;
38+ const resp = await fetchFn ( url ) ;
4139
42- const dom = new JSDOM ( html ) ;
43- let reader = new Readability ( dom . window . document ) ;
44- let article = reader . parse ( ) ;
45- const content = article ?. content || "" ;
46- const markdown = NodeHtmlMarkdown . translate (
47- content ,
48- { } ,
49- undefined ,
50- undefined ,
51- ) ;
40+ // Check if the response is not OK
41+ if ( ! resp . ok ) {
42+ throw new Error ( `HTTP ${ resp . status } ${ resp . statusText } ` ) ;
43+ }
44+
45+ const html = await resp . text ( ) ;
5246
53- const title = article ?. title || url . pathname ;
47+ const dom = new JSDOM ( html ) ;
48+ let reader = new Readability ( dom . window . document ) ;
49+ let article = reader . parse ( ) ;
50+ const content = article ?. content || "" ;
51+ const markdown = NodeHtmlMarkdown . translate (
52+ content ,
53+ { } ,
54+ undefined ,
55+ undefined ,
56+ ) ;
5457
55- return [
56- {
57- icon,
58- description : url . toString ( ) ,
59- content : markdown ,
60- name : title ,
61- uri : {
62- type : "url" ,
63- value : url . toString ( ) ,
64- } ,
58+ const title = article ?. title || url . pathname ;
59+
60+ return [
61+ {
62+ icon,
63+ description : url . toString ( ) ,
64+ content : markdown ,
65+ name : title ,
66+ uri : {
67+ type : "url" ,
68+ value : url . toString ( ) ,
6569 } ,
66- ] ;
67- } catch ( e ) {
68- console . log ( e ) ;
69- return [ ] ;
70- }
70+ } ,
71+ ] ;
7172}
0 commit comments