Skip to content

Commit 66cc201

Browse files
committed
add oeis debug logging
1 parent 43de46a commit 66cc201

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/commands/user/oeis.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,30 @@ export default {
2828
const seq = interaction.options.get("sequence")?.value;
2929
if (!seq) return await interaction.editReply({ content: await __("errors.invalid_argument")(interaction.guildId) });
3030

31-
const f = await fetch(`https://oeis.org/search?q=${seq}&fmt=json`);
31+
const url = `https://oeis.org/search?q=${seq}&fmt=json`;
32+
console.log(`[OEIS] Fetching: ${url}`);
3233

33-
console.log(f);
34+
const f = await fetch(url, {
35+
headers: {
36+
"User-Agent": "Arithmetica-Bot/1.0 (Discord Bot; +https://github.com/NullDev/Arithmetica-Bot)",
37+
Accept: "application/json",
38+
},
39+
});
40+
41+
console.log(`[OEIS] Response status: ${f.status}`);
42+
console.log("[OEIS] Response headers:", Object.fromEntries(f.headers.entries()));
43+
44+
const responseText = await f.text();
45+
console.log("[OEIS] Response body (first 500 chars):", responseText.substring(0, 500));
3446

35-
const results = await f.json();
47+
let results;
48+
try {
49+
results = JSON.parse(responseText);
50+
}
51+
catch {
52+
console.error("[OEIS] Failed to parse JSON. Full response body:", responseText);
53+
throw new Error(`OEIS API returned non-JSON response. Status: ${f.status}. Check logs for full HTML response.`);
54+
}
3655

3756
if (!results || !results.length) return await interaction.editReply({ content: "¯\\_(ツ)_/¯" });
3857

0 commit comments

Comments
 (0)