forked from cartsnitch/cartsnitch
fix(auth): log /health 503 error and surface message in body (CAR-1276)
The /health handler's catch block was empty, so when the DB probe failed we had no log line to diagnose from. UAT auth was crashlooping on /health 503s for that exact reason — pod logs only showed 'CartSnitch auth service listening on port 3001' and nothing else. Add console.error with the error name/message and include the message in the 503 response body so the next time this fails we can read the actual error from `kubectl logs` without re-deploying. This is the dev-side observability half of CAR-1276. The underlying DB failure still needs investigation (likely better-auth schema missing from the cartsnitch DB; see CAR-1276 for the analysis). Tests updated to assert the new error field is present and a string. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
+12
-2
@@ -21,9 +21,19 @@ const server = createServer(async (req, res) => {
|
||||
}
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ status: "ok", db: "reachable" }));
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// Log the actual error so /health 503s are diagnosable from pod logs
|
||||
// (CAR-1276: UAT auth was crashlooping with no log output beyond the
|
||||
// initial "listening on port 3001" line because this catch was empty).
|
||||
console.error(
|
||||
"[auth /health] DB probe failed:",
|
||||
err instanceof Error ? `${err.name}: ${err.message}` : err,
|
||||
);
|
||||
const detail = err instanceof Error ? err.message : "unknown error";
|
||||
res.writeHead(503, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ status: "error", db: "unreachable" }));
|
||||
res.end(
|
||||
JSON.stringify({ status: "error", db: "unreachable", error: detail }),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user