Repository navigation
Keep the response status and original error on passkey errors - #41
Merged
Merged
Conversation
Collaborator
|
Thank you! |
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.
Every failure the package has no kind for reaches the application as a plain
PasskeyErrorwith nothing but a message. A refusal from the server, a request that never reached the server and an authenticator failing on its own all look the same, so the application can only showerror.messageas it arrives.This is a problem for a localized application, and I ran into it while working on one. The server's sentences arrive already translated (
Clave de acceso no reconocida.), while the browser's arrive in English (Failed to fetch), and there is no way to tell which is which in order to translate the latter.In order to make that possible, a response with an error status now throws a
ServerErrorthat carries the response'sstatus, and every other unmapped failure keeps the original error ascause. Both are additive.ServerErrorextendsPasskeyErrorand keeps the same message, andcauseis a new optional property, so existinginstanceof PasskeyErrorchecks anderror.messagekeep working as before. Since the package targets ES2020,causeis declared onPasskeyErroritself instead of relying on ES2022'sErrorOptions.This means that an application can show the server's sentence where the server wrote one, and its own everywhere else. Today the last four cases below all arrive as the same
PasskeyError:We add tests for both in
errors.test.ts,http.test.tsandpasskeys.test.ts, and document them under Typed Errors in the README.