@@ -100,50 +100,43 @@ extension ErrorCode {
100100 public static let InvalidCredentials = ErrorCode ( " invalid_credentials " )
101101}
102102
103- /// Represents an error thrown by Auth, either by the client or the server.
104- public protocol SupabaseAuthError : LocalizedError {
105- var message : String { get }
106- var errorCode : ErrorCode { get }
107- }
108-
109- public struct SupabaseAuthSessionMissingError : SupabaseAuthError {
110- public let errorCode : ErrorCode = . SessionNotFound
111-
112- public let message : String = " Auth session missing. "
113- }
114-
115- /// Error thrown on certain methods when the password used is deemed weak.
116- /// Inspect the reasons to identify what password strength rules are inadequate.
117- public struct SupabaseAuthWeakPasswordError : SupabaseAuthError {
118- public let errorCode : ErrorCode = . WeakPassword
119-
120- public let message : String
121- public let reasons : [ String ]
122- }
123-
124- public struct SupabaseAuthAPIError : SupabaseAuthError {
125- public let message : String
126- public let errorCode : ErrorCode
127-
128- /// The Data response for the underlysing request which caused this error to be thrown.
129- public let underlyngData : Data
130-
131- /// The response for the underlysing request which caused this error to be thrown.
132- public let underlyingResponse : HTTPURLResponse
133-
134- /// The HTTP status code for the response which caused this error to be thrown.
135- public var status : Int { underlyingResponse. statusCode }
136- }
137-
138- public struct SupabaseAuthPKCEGrantCodeExchangeError : SupabaseAuthError {
139- public let errorCode : ErrorCode = . Unknown
103+ public enum AuthError : LocalizedError {
104+ case sessionMissing
105+ case weakPassword( message: String , reasons: [ String ] )
106+ case api(
107+ message: String ,
108+ errorCode: ErrorCode ,
109+ underlyingData: Data ,
110+ underlyingResponse: HTTPURLResponse
111+ )
112+ case pkceGrantCodeExchange( message: String , error: String ? = nil , code: String ? = nil )
113+ case implicitGrantRedirect( message: String )
114+
115+ public var message : String {
116+ switch self {
117+ case . sessionMissing: " Auth session missing. "
118+ case let . weakPassword( message, _) ,
119+ let . api( message, _, _, _) ,
120+ let . pkceGrantCodeExchange( message, _, _) ,
121+ let . implicitGrantRedirect( message) :
122+ message
123+ }
124+ }
140125
141- public let message : String
142- public let error : String ?
143- public let code : String ?
144- }
126+ public var errorCode : ErrorCode {
127+ switch self {
128+ case . sessionMissing: . SessionNotFound
129+ case . weakPassword: . WeakPassword
130+ case let . api( _, errorCode, _, _) : errorCode
131+ case . pkceGrantCodeExchange, . implicitGrantRedirect: . Unknown
132+ }
133+ }
145134
146- public struct SupabaseAuthImplicitGrantRedirectError : SupabaseAuthError {
147- public let errorCode : ErrorCode = . Unknown
148- public var message : String
135+ public var errorDescription : String ? {
136+ if errorCode == . Unknown {
137+ message
138+ } else {
139+ " \( errorCode. rawValue) : \( message) "
140+ }
141+ }
149142}
0 commit comments