Repository navigation
[BY-3731]: key error handlers in Api.configure() by exported Symbols (breaking) - #54
Open
paulambanks wants to merge 7 commits into
Open
paulambanks wants to merge 7 commits into
paulambanks wants to merge 7 commits into
Conversation
commit: |
Member
|
Are we certain this is the best way to do this? I can see that us grabbing a constructor name and removing characters is problematic, but wouldn't the way to do this is to put the constructor names in a Symbol enum and then export the Symbols for use by the consumers? |
tomlewis0
approved these changes
Oct 16, 2026
Contributor
Author
|
done! |
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.
Breaking change: release as 14.0.0
Handlers in
Api.configure()are no longer keyed by name. Import the error type and use it as the key:Api.configure()now throws if any handler other thandefaultis keyed by name, so an app that misses the migration fails at startup instead of silently losing its handlers. That's 4 apps in the dashboard repo (dashboard, marketing, admin, checkin), each only usingaccessDenied. lander only usesdefault, so it needs no change. Handlers on the request like.notFound(), anddefault, are unchanged.Why
Handlers in
Api.configure()were matched by class name, which minification renames, so they never fired in production browser builds. A 401 never redirected to login (Sentry DASHBOARD-5W7, DASHBOARD-5WX, MARKETING-APP-F). Each error type now has a fixed identity, exported as a Symbol, so a misspelt name fails the build instead of being silently ignored.What
AccessDenied,PaymentRequired,Forbidden,NotFound,NotAcceptable,Conflict,Gone,PreconditionFailed,ExpectationFailed,BadDataandTooManyRequests, made withSymbol.forso they still match if both the ESM and CJS builds get loaded.status → error typemap replaces the 11 error classes and the status-to-class lookup.HttpErrorsetse.typefrom it, and both handlers inApi.configure()and on the request are looked up by it. Adding a status is now an export, a map entry and a request method.type, so another library's error with atypefield can't hit a handler.ErrorHandlerstype is keyed by the error types plusdefault, with the catch-all string key removed.Api.configure(), a table of status / handler on the request / key inApi.configure(), and an "Upgrading to 14" section.Testing
choosing which handler handles a failed request, each describing a general rule (e.g.when configure() has a handler for the status and the request only has a default), one assertion each, plusconfigure()rejecting name keys and an unhandled failure being logged once.configure()before the request, ignoring handlers on the request, ignoringdefaultinconfigure(), not settinge.type, not rejecting name keys, logging twice, accepting name keys at lookup). The first six each fail the suite. The last can't be reached, becauseconfigure()rejects name keys first.MISSING_EXPORT),configure()throws on a name key, and a minified build sends a 401 and a 404 to their handlers inconfigure(), a 500 todefault, and lets.notFound()on the request win. TypeScript rejects both a misspelt import and a string key.constructor.name.