Skip to content

AuthError error description should be exhaustive #505

@peterkos

Description

@peterkos

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?

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions