diff --git a/Sources/CoreATProtocol/OAuth/ATProtoOAuth.swift b/Sources/CoreATProtocol/OAuth/ATProtoOAuth.swift index 61982fc..e6726e0 100644 --- a/Sources/CoreATProtocol/OAuth/ATProtoOAuth.swift +++ b/Sources/CoreATProtocol/OAuth/ATProtoOAuth.swift @@ -57,7 +57,7 @@ public struct ATProtoAuthStorage: Sendable { } } -public enum ATProtoOAuthError: Error, Sendable { +public enum ATProtoOAuthError: LocalizedError, Sendable { case invalidConfiguration case authenticationFailed(String) case identityResolutionFailed @@ -68,6 +68,31 @@ public enum ATProtoOAuthError: Error, Sendable { case malformedAuthorizationCallback case tokenRequestFailed(String) case invalidTokenResponse + + public var errorDescription: String? { + switch self { + case .invalidConfiguration: + "OAuth configuration is invalid" + case .authenticationFailed(let detail): + "Authentication failed: \(detail)" + case .identityResolutionFailed: + "Failed to resolve AT Protocol identity" + case .privateKeyExportFailed: + "Failed to export DPoP private key" + case .missingRequiredScope(let scope): + "Missing required scope: \(scope)" + case .subjectMismatch(let expected, let actual): + "Subject mismatch — expected \(expected), got \(actual)" + case .issuerMismatch(let expected, let actual): + "Issuer mismatch — expected \(expected), got \(actual)" + case .malformedAuthorizationCallback: + "Authorization callback URL is malformed" + case .tokenRequestFailed(let detail): + "Token request failed: \(detail)" + case .invalidTokenResponse: + "Invalid token response from server" + } + } } /// Type alias for the user authenticator callback