Skip to content

fix: distinguish account not-found (404) from system errors (500) in discovery#205

Open
semantabhandari wants to merge 1 commit into
mainfrom
fix/account-discovery-error-handling
Open

fix: distinguish account not-found (404) from system errors (500) in discovery#205
semantabhandari wants to merge 1 commit into
mainfrom
fix/account-discovery-error-handling

Conversation

@semantabhandari

Copy link
Copy Markdown
Collaborator

Problem: The account-discovery onRequest hook caught every failure with one handler that always returned 404 Account not found. Genuine unknown-subdomain traffic and real system failures (DB outage, timeout, bug) were indistinguishable.

Change: discoverAccount now throws a typed AccountNotFoundError for genuine not-found (it still returns null for excluded routes and still propagates infra errors). The hook maps AccountNotFoundError to the existing 404 { error: { message: "Account not found" } } at debug severity (never alerts), and rethrows everything else so @prefabs.tech/fastify-error-handler's setErrorHandler logs it at error and returns 500. Severity for system errors is owned centrally; the hook no longer logs raw caught errors.

Backward compatibility: The 404 status and exact body shape are unchanged. Only previously-mislabeled system failures change: 404/warn → 500/error. AccountNotFoundError is exported for consumers.

Tests: Unit tests for discoverAccount's branches (found / not-found / excluded / DB failure) and an integration test driving the real hook + central error handler asserting 404-low-severity vs 500-error-level.

…discovery

Account discovery caught every failure with one handler that always returned
404 Account not found, conflating genuine unknown-subdomain traffic with real
system failures (DB outage, timeout, bug). Lowering the log to warn to quiet
unknown-subdomain noise made outages silent 404 + warn: no alert, wrong status.

discoverAccount now throws a typed AccountNotFoundError for genuine not-found
(it still returns null for excluded routes and still propagates infra errors).
The hook maps AccountNotFoundError to the existing 404 body at debug severity
and rethrows everything else so the central error handler logs it at error and
returns 500. The 404 status and body shape are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant