Skip to content

Commit

Permalink
fix(auth): add localized description to AWSCognitoAuthError
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Dec 5, 2024
1 parent a2dfdf0 commit eae02ee
Showing 1 changed file with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)"
}
}

0 comments on commit eae02ee

Please sign in to comment.