fix(lolschedule): structured error logging for cargoquery failures

Swaps the best-effort console.warn for JSON log lines emitted via
console.log so Workers Observability + wrangler tail surface the real
cause (HTTP status, API error info, or non-JSON body) when /lol_today
and /lol_week fall into the error branch.
This commit is contained in:
2026-04-21 09:51:43 +07:00
committed by Tien Nguyen Minh
parent 57c6528af7
commit 436664c8a1
3 changed files with 41 additions and 8 deletions
+6 -2
View File
@@ -7,10 +7,12 @@ import {
import { makeFakeKv } from "../../fakes/fake-kv-namespace.js";
function cargoResponse(rows) {
const payload = { cargoquery: rows.map((title) => ({ title })) };
return {
ok: true,
status: 200,
json: async () => ({ cargoquery: rows.map((title) => ({ title })) }),
text: async () => JSON.stringify(payload),
json: async () => payload,
};
}
@@ -53,10 +55,12 @@ describe("fetchMatchesInRange", () => {
});
it("surfaces Leaguepedia API error field", async () => {
const errPayload = { error: { info: "Bad query", code: "x" } };
global.fetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ error: { info: "Bad query", code: "x" } }),
text: async () => JSON.stringify(errPayload),
json: async () => errPayload,
});
await expect(
fetchMatchesInRange(new Date("2026-04-21T00:00:00Z"), new Date("2026-04-22T00:00:00Z")),