fix: distinguish account not-found (404) from system errors (500) in discovery#205
Open
semantabhandari wants to merge 1 commit into
Open
fix: distinguish account not-found (404) from system errors (500) in discovery#205semantabhandari wants to merge 1 commit into
semantabhandari wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: The account-discovery
onRequesthook caught every failure with one handler that always returned 404Account not found. Genuine unknown-subdomain traffic and real system failures (DB outage, timeout, bug) were indistinguishable.Change:
discoverAccountnow throws a typedAccountNotFoundErrorfor genuine not-found (it still returnsnullfor excluded routes and still propagates infra errors). The hook mapsAccountNotFoundErrorto 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.
AccountNotFoundErroris 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.