From eae02eebc30b8d3ee54fb37695029282c9898c07 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <6162866+harsh62@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:30:32 -0500 Subject: [PATCH] fix(auth): add localized description to AWSCognitoAuthError --- .../Models/Errors/AWSCognitoAuthError.swift | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift index ffa1315432..0aba6cfb02 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift @@ -13,7 +13,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 +40,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. @@ -110,3 +110,80 @@ public enum AWSCognitoAuthError: Error { /// The WebAuthm configuration is missing or incomplete case webAuthnConfigurationMissing } + +extension AWSCognitoAuthError { + public var localizedDescription: 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 encounters an invalid AWS Lambda response or encounters 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 any 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 WebAuthm configuration is missing or incomplete." + } + return "\(String(describing: Self.self)).\(self): \(message)" + } +}