fix(GRO-424): add try/catch around reinitAuth() calls

reinitAuth() can throw if BETTER_AUTH_SECRET is missing, causing
an unhandled rejection that returns an HTML error page instead of
JSON. Wrap both PUT and DELETE handlers in try/catch to return a
proper JSON error response.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
groombook-engineer[bot]
2026-04-03 11:37:27 +00:00
parent ae920aa347
commit 1f2a73cb44
+12 -2
View File
@@ -88,7 +88,12 @@ authProviderRouter.put(
if (!row) return c.json({ error: "Failed to create auth provider config" }, 500);
await reinitAuth();
try {
await reinitAuth();
} catch (err) {
const message = err instanceof Error ? err.message : "Unknown error";
return c.json({ error: `Failed to reinitialize auth: ${message}` }, 500);
}
return c.json({
id: row.id,
@@ -145,7 +150,12 @@ authProviderRouter.delete(
async (c) => {
const db = getDb();
await db.delete(authProviderConfig);
await reinitAuth();
try {
await reinitAuth();
} catch (err) {
const message = err instanceof Error ? err.message : "Unknown error";
return c.json({ error: `Failed to reinitialize auth: ${message}` }, 500);
}
return c.json({ ok: true });
}
);