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:
@@ -88,7 +88,12 @@ authProviderRouter.put(
|
|||||||
|
|
||||||
if (!row) return c.json({ error: "Failed to create auth provider config" }, 500);
|
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({
|
return c.json({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
@@ -145,7 +150,12 @@ authProviderRouter.delete(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
await db.delete(authProviderConfig);
|
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 });
|
return c.json({ ok: true });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user