-
-
Notifications
You must be signed in to change notification settings - Fork 200
feat(auth): add support for error codes and refactor AuthError
#518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| try await trace(using: logger) { | ||
| guard let currentSession = try sessionStorage.get() else { | ||
| throw AuthError.sessionNotFound | ||
| throw AuthError.sessionMissing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could technically be considered a breaking change, but I will leave it up to you what to do with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really since I added a static let sessionNotFound: AuthError { .sessionMissing }, and deprecated it.
In a Swift enum, cases and static let are "kinda" equivalent.
If client is expecting a sessionNotFound, he'll start getting a deprecation warning.
What kind of change does this PR introduce?
This PR includes some changes on Auth error system, I tried my best to keep it compatible and without breaking changes.
If you see anything that could be a breaking change, please let me know.
What is the new behavior?
Error codes
Introduce
ErrorCodetype as a raw representable string, added static properties for each of the known error codes. Since error codes are raw representable strings, if an unknown error code is returned, decoding is going to work fine.Deprecated errors
missingExpClaimerror deprecated, it is never thrown now, but I kept it for retro-compatibilitymalformedJWTerror deprecated, it is never thrown now, but I kept it for retro-compatibilitysessionNotFounderror deprecated, usesessionMissinginsteadpkce(_:)error deprecated, usepkceGrantCodeExchangeinsteadinvalidImplicitGrantFlowURLerror deprecated, useimplicitGrantRedirectinsteadmissingURLerror deprecated, it is never thrown, but I kept it for retro-compatibilityapi(_:)error deprecated, useapi(message:errorCode:underlyingData:underlyingResponse:)insteadAdded errors
sessionMissingthrown when a session is required to proceed, but none was found, either thrown by the client, or returned by the server.weakPasswordthrown when password is deemed weak, check associated reasons to know why.api(message:errorCode:underlyingData:underlyingResponse:)thrown by API when an error occurs, checkerrorCodeto know more, or useunderlyingDataorunderlyingResponsefor access to the response which originated this error.pkceGrantCodeExchangethrown when an error happens during PKCE grant flow.implicitGrantRedirectthrown when an error happens during implicit grant flow.