diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift index ffa1315432..5f3553979c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift @@ -5,6 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // +import Foundation + public enum AWSCognitoAuthError: Error { /// User not found in the system. @@ -13,7 +15,7 @@ public enum AWSCognitoAuthError: Error { /// User not confirmed in the system. case userNotConfirmed - /// Username does not exists in the system. + /// Username already exists in the system. case usernameExists /// Alias already exists in the system. @@ -40,7 +42,7 @@ public enum AWSCognitoAuthError: Error { /// Amazon Cognito cannot find a multi-factor authentication (MFA) method. case mfaMethodNotFound - /// Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool. + /// Software token (TOTP) multi-factor authentication (MFA) is not enabled for the user pool. case softwareTokenMFANotEnabled /// Required to reset the password of the user. @@ -55,7 +57,7 @@ public enum AWSCognitoAuthError: Error { /// The user has made too many requests for a given operation. case requestLimitExceeded - /// Amazon Cognito service encounters an invalid AWS Lambda response or encounters an + /// Amazon Cognito service encountered an invalid AWS Lambda response or encountered an /// unexpected exception with the AWS Lambda service. case lambda @@ -71,7 +73,7 @@ public enum AWSCognitoAuthError: Error { /// Requested resource is not available with the current account setup. case invalidAccountTypeException - /// Request was not completed because of any network related issue + /// Request was not completed because of a network related issue case network /// SMS role related issue @@ -107,6 +109,83 @@ public enum AWSCognitoAuthError: Error { /// The relying party ID doesn't match case webAuthnRelyingPartyMismatch - /// The WebAuthm configuration is missing or incomplete + /// The WebAuthn configuration is missing or incomplete case webAuthnConfigurationMissing } + +extension AWSCognitoAuthError: LocalizedError { + public var errorDescription: String? { + var message: String = "" + switch self { + case .userNotFound: + message = "User not found in the system." + case .userNotConfirmed: + message = "User not confirmed in the system." + case .usernameExists: + message = "Username already exists in the system." + case .aliasExists: + message = "Alias already exists in the system." + case .codeDelivery: + message = "Error in delivering the confirmation code." + case .codeMismatch: + message = "Confirmation code entered is not correct." + case .codeExpired: + message = "Confirmation code has expired." + case .invalidParameter: + message = "One or more parameters are incorrect." + case .invalidPassword: + message = "Password given is invalid." + case .limitExceeded: + message = "Limit exceeded for the requested AWS resource." + case .mfaMethodNotFound: + message = "Amazon Cognito cannot find a multi-factor authentication (MFA) method." + case .softwareTokenMFANotEnabled: + message = "Software token (TOTP) multi-factor authentication (MFA) is not enabled for the user pool." + case .passwordResetRequired: + message = "Required to reset the password of the user." + case .resourceNotFound: + message = "Amazon Cognito service cannot find the requested resource." + case .failedAttemptsLimitExceeded: + message = "The user has made too many failed attempts for a given action." + case .requestLimitExceeded: + message = "The user has made too many requests for a given operation." + case .lambda: + message = "Amazon Cognito service encountered an invalid AWS Lambda response or encountered an unexpected exception with the AWS Lambda service." + case .deviceNotTracked: + message = "Device is not tracked." + case .errorLoadingUI: + message = "Error in loading the web UI." + case .userCancelled: + message = "User cancelled the step." + case .invalidAccountTypeException: + message = "Requested resource is not available with the current account setup." + case .network: + message = "Request was not completed because of a network related issue." + case .smsRole: + message = "SMS role related issue." + case .emailRole: + message = "Email role related issue." + case .externalServiceException: + message = "An external service like facebook/twitter threw an error." + case .limitExceededException: + message = "Limit exceeded exception. Thrown when the total number of user pools has exceeded a preset limit." + case .resourceConflictException: + message = "Thrown when a user tries to use a login which is already linked to another account." + case .webAuthnChallengeNotFound: + message = "The WebAuthn credentials don't match an existing request." + case .webAuthnClientMismatch: + message = "The client doesn't support WebAuhn authentication." + case .webAuthnNotSupported: + message = "WebAuthn is not supported on this device." + case .webAuthnNotEnabled: + message = "WebAuthn is not enabled." + case .webAuthnOriginNotAllowed: + message = "The device origin is not registered as an allowed origin." + case .webAuthnRelyingPartyMismatch: + message = "The relying party ID doesn't match." + case .webAuthnConfigurationMissing: + message = "The WebAuthn configuration is missing or incomplete." + } + return "\(String(describing: Self.self)).\(self): \(message)" + } +}