harden(eoc-push): fånga mappningsfel så pushen aldrig kastar

This commit is contained in:
Sven (AAMOS AI)
2026-08-11 18:44:01 +07:00
parent 4adde4faff
commit ac919e9425
2 changed files with 31 additions and 1 deletions
+10 -1
View File
@@ -139,7 +139,16 @@ export async function pushOpsSummaryToEoc(redis: Redis): Promise<EocPushResult>
return { ok: false, status: null, error: "ops summary cache is not a JSON object" };
}
const body = JSON.stringify(mapPayloadForEoc(parsed as Record<string, unknown>));
let body: string;
try {
body = JSON.stringify(mapPayloadForEoc(parsed as Record<string, unknown>));
} catch (err) {
return {
ok: false,
status: null,
error: `payload mapping failed: ${err instanceof Error ? err.message : String(err)}`,
};
}
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), EOC_PUSH_TIMEOUT_MS);
+21
View File
@@ -135,4 +135,25 @@ describe("pushOpsSummaryToEoc", () => {
globalThis.fetch = originalFetch;
}
});
it("does not throw when payload mapping fails", async () => {
process.env.EOC_URL = "https://eoc.example.com";
process.env.EOC_PUSH_TOKEN = "tok";
await redis.set(
"ops:summary:cache",
JSON.stringify({
as_of: new Date().toISOString(),
app: { app: "cibello" },
wall: { boards: [{ title: 123, tiles: "nej" }] },
}),
"EX",
60,
);
await expect(pushOpsSummaryToEoc(redis)).resolves.toEqual({
ok: false,
status: null,
error: expect.stringMatching(/payload mapping failed/),
});
});
});