Skip to content

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Aug 29, 2024

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 ErrorCode type 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

  • missingExpClaim error deprecated, it is never thrown now, but I kept it for retro-compatibility
  • malformedJWT error deprecated, it is never thrown now, but I kept it for retro-compatibility
  • sessionNotFound error deprecated, use sessionMissing instead
  • pkce(_:) error deprecated, use pkceGrantCodeExchange instead
  • invalidImplicitGrantFlowURL error deprecated, use implicitGrantRedirect instead
  • missingURL error deprecated, it is never thrown, but I kept it for retro-compatibility
  • api(_:) error deprecated, use api(message:errorCode:underlyingData:underlyingResponse:) instead

Added errors

  • sessionMissing thrown when a session is required to proceed, but none was found, either thrown by the client, or returned by the server.
  • weakPassword thrown when password is deemed weak, check associated reasons to know why.
  • api(message:errorCode:underlyingData:underlyingResponse:) thrown by API when an error occurs, check errorCode to know more, or use underlyingData or underlyingResponse for access to the response which originated this error.
  • pkceGrantCodeExchange thrown when an error happens during PKCE grant flow.
  • implicitGrantRedirect thrown when an error happens during implicit grant flow.

@grdsdev grdsdev marked this pull request as ready for review September 2, 2024 11:49
@grdsdev grdsdev requested a review from dshukertjr September 2, 2024 12:28
@@ -40,7 +40,7 @@ private actor LiveSessionManager {
func session() async throws -> Session {
try await trace(using: logger) {
guard let currentSession = try sessionStorage.get() else {
throw AuthError.sessionNotFound
throw AuthError.sessionMissing
Copy link
Member

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.

Copy link
Contributor Author

@grdsdev grdsdev Sep 3, 2024

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.

@grdsdev grdsdev linked an issue Sep 3, 2024 that may be closed by this pull request
@grdsdev grdsdev merged commit 7601e17 into main Sep 6, 2024
5 checks passed
@grdsdev grdsdev deleted the auth-error-codes branch September 6, 2024 12:07
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.

[Auth] Add support for error codes
2 participants