fix(site): degrade gracefully when site API returns 500 (BIT-33541)
The root layout and home page SSR fetch /v1/public/site on every request. When the API has a transient Postgres outage (P2037 pool exhaustion), it returns 500 and the site rethrows, which instrumentation.ts reports to errors.bitreport.pt — creating an error loop (8 repeats per cycle). Catch the 500 in the layout (like the existing 404 path) and render a minimal 'temporarily unavailable' shell without throwing, so onRequestError never fires. Also make load() return null on transient errors instead of throwing, as a safety net. Paperclip-Issue: BIT-33541
This commit is contained in:
1 parent
6182c03cd5
commit
03459fda8d
3 files changed
+21
-4
No files matched your search
@@ -19,6 +19,8 @@ export async function load(q: string, sport: string) {
|
||||
]);
|
||||
} catch (err) {
|
||||
if (err instanceof NotFound) return null;
|
||||
throw err;
|
||||
// Transient API/DB errors (e.g. Postgres pool exhaustion) degrade to null so the page shows
|
||||
// a neutral message instead of crashing and feeding the error loop reporter.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,21 @@ export default async function RootLayout({ children }: { children: ReactNode })
|
||||
try {
|
||||
site = await getSite();
|
||||
} catch (err) {
|
||||
if (!(err instanceof NotFound)) throw err;
|
||||
if (!(err instanceof NotFound)) {
|
||||
// Transient API/DB errors (e.g. Postgres pool exhaustion) must not crash the layout —
|
||||
// instrumentation.ts reports every thrown error to errors.bitreport.pt, creating an error
|
||||
// loop. Render a minimal shell so the page returns 200 without a thrown error.
|
||||
return (
|
||||
<html lang="pt">
|
||||
<body>
|
||||
<ErrorReporter />
|
||||
<main className="wrap empty">
|
||||
<p>Temporariamente indisponível. Tenta novamente dentro de uns minutos.</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
// The events domain (events.photoreport.pt) has no storefront: its event pages (QR page, kiosk) and the
|
||||
// archive's sign-in pages stand alone.
|
||||
if (path.startsWith("/e/") || path.startsWith("/arquivo/")) {
|
||||
|
||||
@@ -57,11 +57,12 @@ describe("home load — graceful degradation", () => {
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("throws when the site API returns 500 (real error)", async () => {
|
||||
it("returns null when the site API returns 500 (transient error, graceful degradation)", async () => {
|
||||
mockFetch({
|
||||
"/v1/public/site": { status: 500, body: {} },
|
||||
});
|
||||
|
||||
await expect(load("", "")).rejects.toThrow("/v1/public/site: 500");
|
||||
const result = await load("", "");
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user