fix(api): add error handling and null guard to /api/staff/me

Wrap c.json() in try/catch to surface any remaining serialization
errors rather than crashing with a generic 500. Also change the null-
staff guard from 404 → 500 since a missing staff context is an
internal error, not a not-found case.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
groombook-ci[bot]
2026-03-29 20:38:18 +00:00
parent 23273a0ab8
commit 7523d4cbd9
+8 -1
View File
@@ -24,8 +24,11 @@ const updateStaffSchema = z.object({
}); });
staffRouter.get("/me", async (c) => { staffRouter.get("/me", async (c) => {
try {
const staffRow = c.get("staff"); const staffRow = c.get("staff");
if (!staffRow) return c.json({ error: "Staff record not found" }, 404); if (!staffRow) {
return c.json({ error: "Staff record not found in context" }, 500);
}
// Explicitly pick serializable fields to avoid BigInt/Date/undefined serialization issues // Explicitly pick serializable fields to avoid BigInt/Date/undefined serialization issues
return c.json({ return c.json({
id: staffRow.id, id: staffRow.id,
@@ -39,6 +42,10 @@ staffRouter.get("/me", async (c) => {
createdAt: staffRow.createdAt, createdAt: staffRow.createdAt,
updatedAt: staffRow.updatedAt, updatedAt: staffRow.updatedAt,
}); });
} catch (err) {
console.error("[/api/staff/me] error:", err, "staffRow:", c.get("staff"));
return c.json({ error: "Internal error", detail: String(err) }, 500);
}
}); });
staffRouter.get("/", async (c) => { staffRouter.get("/", async (c) => {