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:
@@ -24,21 +24,28 @@ const updateStaffSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
staffRouter.get("/me", async (c) => {
|
staffRouter.get("/me", async (c) => {
|
||||||
const staffRow = c.get("staff");
|
try {
|
||||||
if (!staffRow) return c.json({ error: "Staff record not found" }, 404);
|
const staffRow = c.get("staff");
|
||||||
// Explicitly pick serializable fields to avoid BigInt/Date/undefined serialization issues
|
if (!staffRow) {
|
||||||
return c.json({
|
return c.json({ error: "Staff record not found in context" }, 500);
|
||||||
id: staffRow.id,
|
}
|
||||||
name: staffRow.name,
|
// Explicitly pick serializable fields to avoid BigInt/Date/undefined serialization issues
|
||||||
email: staffRow.email,
|
return c.json({
|
||||||
role: staffRow.role,
|
id: staffRow.id,
|
||||||
active: staffRow.active,
|
name: staffRow.name,
|
||||||
isSuperUser: staffRow.isSuperUser,
|
email: staffRow.email,
|
||||||
userId: staffRow.userId,
|
role: staffRow.role,
|
||||||
oidcSub: staffRow.oidcSub,
|
active: staffRow.active,
|
||||||
createdAt: staffRow.createdAt,
|
isSuperUser: staffRow.isSuperUser,
|
||||||
updatedAt: staffRow.updatedAt,
|
userId: staffRow.userId,
|
||||||
});
|
oidcSub: staffRow.oidcSub,
|
||||||
|
createdAt: staffRow.createdAt,
|
||||||
|
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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user