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 1/3] 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)" + } +} From 28adfbfec947dba94d15ab11ed0a03b10b89ef49 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <6162866+harsh62@users.noreply.github.com> Date: Thu, 5 Dec 2024 00:17:19 -0500 Subject: [PATCH 2/3] update --- .../Models/Errors/AWSCognitoAuthError.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift index 0aba6cfb02..d859ebf8f1 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. @@ -111,8 +113,8 @@ public enum AWSCognitoAuthError: Error { case webAuthnConfigurationMissing } -extension AWSCognitoAuthError { - public var localizedDescription: String { +extension AWSCognitoAuthError: LocalizedError { + public var errorDescription: String? { var message: String = "" switch self { case .userNotFound: From 98f09f06da0cbfdb5aa9f23a5319fae7c84ea1ab Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <6162866+harsh62@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:16:11 -0500 Subject: [PATCH 3/3] update messages --- .../Models/Errors/AWSCognitoAuthError.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift index d859ebf8f1..5f3553979c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift @@ -57,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 @@ -73,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 @@ -109,7 +109,7 @@ 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 } @@ -150,7 +150,7 @@ extension AWSCognitoAuthError: LocalizedError { 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." + 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: @@ -160,7 +160,7 @@ extension AWSCognitoAuthError: LocalizedError { 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." + message = "Request was not completed because of a network related issue." case .smsRole: message = "SMS role related issue." case .emailRole: @@ -184,7 +184,7 @@ extension AWSCognitoAuthError: LocalizedError { case .webAuthnRelyingPartyMismatch: message = "The relying party ID doesn't match." case .webAuthnConfigurationMissing: - message = "The WebAuthm configuration is missing or incomplete." + message = "The WebAuthn configuration is missing or incomplete." } return "\(String(describing: Self.self)).\(self): \(message)" }