-
-
Notifications
You must be signed in to change notification settings - Fork 173
Closed
Description
Chore
Describe the chore
Given that every error is "known", it should be possible to always have an errorDescription. This is all correctly implemented, BUT errorDescription is still optional -- there is no reason to be optional if we never return nil
, no?
supabase-swift/Sources/Auth/AuthError.swift
Lines 53 to 65 in 4c966ea
public var errorDescription: String? { | |
switch self { | |
case let .api(error): error.errorDescription ?? error.msg ?? error.error | |
case .missingExpClaim: "Missing expiration claim in the access token." | |
case .malformedJWT: "A malformed JWT received." | |
case .sessionNotFound: "Unable to get a valid session." | |
case let .pkce(reason): reason.errorDescription | |
case .invalidImplicitGrantFlowURL: "Not a valid implicit grant flow url." | |
case .missingURL: "Missing URL." | |
case .invalidRedirectScheme: "Invalid redirect scheme." | |
} | |
} | |
} |
Additional context
This would allow for consistent error handling:
let supabaseResponse: Supabase.AuthResponse
do {
supabaseResponse = try await client.auth.signUp(/* ... */)
} catch let error as AuthError {
return .failure(.supabaseError(error.errorDescription))
} catch {
return .failure(.supabaseError(error.localizedDescription))
}
Versus currently, where this workaround is needed:
let supabaseResponse: Supabase.AuthResponse
do {
supabaseResponse = try await client.auth.signUp(/* ... */)
} catch let error as AuthError {
return .failure(.supabaseError(error.errorDescription ?? "Who the hell knows what happened"))
} catch {
return .failure(.supabaseError(error.localizedDescription))
}
Ideally once Swift 6 comes out, typed throws are implemented too but that's probably best for a separate issue :)
Metadata
Metadata
Assignees
Labels
No labels