Last active
October 17, 2024 03:19
-
-
Save Catherine-K-George/11a94271bd0cff282e019cd2613d089b to your computer and use it in GitHub Desktop.
Swift AWS Cognito exception handler with customized descriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWSCognitoIdentityProvider | |
extension Error { | |
var customizedDescription: String { | |
let nsError = self as NSError | |
if nsError.domain == AWSCognitoIdentityProviderErrorDomain, let code = AWSCognitoIdentityProviderErrorType(rawValue: nsError.code) { | |
switch code { | |
case .expiredCode: return "Verification code has expired. Please try again" | |
case .codeMismatch: return "Incorrect verification code. Please enter the correct code to continue." | |
case .notAuthorized: return "Authentication failed. Please enter the correct credentials to continue." | |
case .usernameExists: return "Username already exists." | |
case .invalidPassword: return "Invalid password. Please try again." | |
case .userNotConfirmed: return "User not confirmed. Please verify your account." | |
default: return nsError.userInfo["message"] as? String ?? "AWS cognito failed with error code: \(nsError.code)" | |
} | |
} | |
return localizedDescription | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment