File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -39,16 +39,34 @@ const JISHO_PROXY_BASE = import.meta.env.PROD
3939async function fetchKanjiFromJisho ( reading : string ) : Promise < string [ ] > {
4040 if ( ! reading ) return [ ] ;
4141 const jishoUrl = "https://jisho.org/api/v1/search/words?keyword=" + encodeURIComponent ( reading ) ;
42- const proxyUrl = JISHO_PROXY_BASE + encodeURIComponent ( jishoUrl ) ;
42+
43+ const proxyUrl = import . meta. env . PROD
44+ ? JISHO_PROXY_BASE + jishoUrl
45+ : JISHO_PROXY_BASE + "?url=" + encodeURIComponent ( jishoUrl ) ;
4346
4447 try {
45- const res = await fetch ( proxyUrl ) ;
46- if ( ! res . ok ) return [ ] ;
48+ const res = await fetch ( proxyUrl , {
49+ headers : {
50+ "X-Requested-With" : "XMLHttpRequest" ,
51+ } ,
52+ } ) ;
53+
54+ if ( ! res . ok ) {
55+ console . error ( `Error fetching from proxy: ${ res . status } ${ res . statusText } ` ) ;
56+ try {
57+ const errorText = await res . text ( ) ;
58+ console . error ( "Proxy error response:" , errorText ) ;
59+ } catch ( e ) {
60+ console . error ( "Could not read error response text:" , e ) ;
61+ }
62+ return [ ] ;
63+ }
4764 const json = ( await res . json ( ) ) as JishoResponse ;
4865 if ( ! json ?. data ) return [ ] ;
4966 const set = new Set ( json . data . map ( ( e ) => e . japanese [ 0 ] . word || e . japanese [ 0 ] . reading ) ) ;
5067 return Array . from ( set ) ;
51- } catch {
68+ } catch ( error ) {
69+ console . error ( "Error in fetchKanjiFromJisho:" , error ) ;
5270 return [ ] ;
5371 }
5472}
You can’t perform that action at this time.
0 commit comments