refactor(errors): route fatal app errors

This commit is contained in:
ZacharyZhang-NY committed 2026-04-24 03:31:39 -04:00
1 parent ead9475b71
commit 38e2807f6c
6 files changed
+84 -27

No files matched your search

+1 -21
View File
@@ -78,26 +78,6 @@ export function createBrowserActionService({
});
}
/**
* Returns the approval record for `approvalId`, or null if the record is
* missing. Isolates the "approval row disappeared" case so the caller does
* not need to nest a try/catch around the state machine.
*/
function getApprovalOrNull(approvalId: string): ReturnType<typeof db.core.approvals.getApprovalRecord> | null {
try {
return db.core.approvals.getApprovalRecord(approvalId);
} catch (err) {
const classified = classifyUnknownError(err, {
kind: "recoverable",
code: "browser_action.approval.lookup_failed",
message: `getApprovalRecord failed for ${approvalId}`,
context: { approvalId },
});
log.warn(`[${classified.code}]`, classified.message, classified.context);
return null;
}
}
async function dispatchBrowserAction(actionId: string, companyId: string) {
const action = db.core.social.getBrowserAction(actionId, companyId);
if (!action) {
@@ -107,7 +87,7 @@ export function createBrowserActionService({
throw new Error(`Browser action ${actionId} is ${action.status} and cannot be dispatched.`);
}
if (action.approvalId) {
const approval = getApprovalOrNull(action.approvalId);
const approval = db.core.approvals.getApprovalRecord(action.approvalId);
if (!approval || approval.companyId !== companyId) {
throw new Error(`Browser action approval ${action.approvalId} does not belong to company ${companyId}.`);
}