Skip to content

Commit 5cf431b

Browse files
committed
more fighting with proxies
1 parent 4e65963 commit 5cf431b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/IMEField.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,34 @@ const JISHO_PROXY_BASE = import.meta.env.PROD
3939
async 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
}

0 commit comments

Comments
 (0)