Skip to content

Commit 89d3b72

Browse files
authored
fix(auth): add localized description to AWSCognitoAuthError (#3929)
* fix(auth): add localized description to AWSCognitoAuthError * update * update messages
1 parent e0aabad commit 89d3b72

File tree

1 file changed

+84
-5
lines changed

1 file changed

+84
-5
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Errors/AWSCognitoAuthError.swift

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
import Foundation
9+
810
public enum AWSCognitoAuthError: Error {
911

1012
/// User not found in the system.
@@ -13,7 +15,7 @@ public enum AWSCognitoAuthError: Error {
1315
/// User not confirmed in the system.
1416
case userNotConfirmed
1517

16-
/// Username does not exists in the system.
18+
/// Username already exists in the system.
1719
case usernameExists
1820

1921
/// Alias already exists in the system.
@@ -40,7 +42,7 @@ public enum AWSCognitoAuthError: Error {
4042
/// Amazon Cognito cannot find a multi-factor authentication (MFA) method.
4143
case mfaMethodNotFound
4244

43-
/// Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool.
45+
/// Software token (TOTP) multi-factor authentication (MFA) is not enabled for the user pool.
4446
case softwareTokenMFANotEnabled
4547

4648
/// Required to reset the password of the user.
@@ -55,7 +57,7 @@ public enum AWSCognitoAuthError: Error {
5557
/// The user has made too many requests for a given operation.
5658
case requestLimitExceeded
5759

58-
/// Amazon Cognito service encounters an invalid AWS Lambda response or encounters an
60+
/// Amazon Cognito service encountered an invalid AWS Lambda response or encountered an
5961
/// unexpected exception with the AWS Lambda service.
6062
case lambda
6163

@@ -71,7 +73,7 @@ public enum AWSCognitoAuthError: Error {
7173
/// Requested resource is not available with the current account setup.
7274
case invalidAccountTypeException
7375

74-
/// Request was not completed because of any network related issue
76+
/// Request was not completed because of a network related issue
7577
case network
7678

7779
/// SMS role related issue
@@ -107,6 +109,83 @@ public enum AWSCognitoAuthError: Error {
107109
/// The relying party ID doesn't match
108110
case webAuthnRelyingPartyMismatch
109111

110-
/// The WebAuthm configuration is missing or incomplete
112+
/// The WebAuthn configuration is missing or incomplete
111113
case webAuthnConfigurationMissing
112114
}
115+
116+
extension AWSCognitoAuthError: LocalizedError {
117+
public var errorDescription: String? {
118+
var message: String = ""
119+
switch self {
120+
case .userNotFound:
121+
message = "User not found in the system."
122+
case .userNotConfirmed:
123+
message = "User not confirmed in the system."
124+
case .usernameExists:
125+
message = "Username already exists in the system."
126+
case .aliasExists:
127+
message = "Alias already exists in the system."
128+
case .codeDelivery:
129+
message = "Error in delivering the confirmation code."
130+
case .codeMismatch:
131+
message = "Confirmation code entered is not correct."
132+
case .codeExpired:
133+
message = "Confirmation code has expired."
134+
case .invalidParameter:
135+
message = "One or more parameters are incorrect."
136+
case .invalidPassword:
137+
message = "Password given is invalid."
138+
case .limitExceeded:
139+
message = "Limit exceeded for the requested AWS resource."
140+
case .mfaMethodNotFound:
141+
message = "Amazon Cognito cannot find a multi-factor authentication (MFA) method."
142+
case .softwareTokenMFANotEnabled:
143+
message = "Software token (TOTP) multi-factor authentication (MFA) is not enabled for the user pool."
144+
case .passwordResetRequired:
145+
message = "Required to reset the password of the user."
146+
case .resourceNotFound:
147+
message = "Amazon Cognito service cannot find the requested resource."
148+
case .failedAttemptsLimitExceeded:
149+
message = "The user has made too many failed attempts for a given action."
150+
case .requestLimitExceeded:
151+
message = "The user has made too many requests for a given operation."
152+
case .lambda:
153+
message = "Amazon Cognito service encountered an invalid AWS Lambda response or encountered an unexpected exception with the AWS Lambda service."
154+
case .deviceNotTracked:
155+
message = "Device is not tracked."
156+
case .errorLoadingUI:
157+
message = "Error in loading the web UI."
158+
case .userCancelled:
159+
message = "User cancelled the step."
160+
case .invalidAccountTypeException:
161+
message = "Requested resource is not available with the current account setup."
162+
case .network:
163+
message = "Request was not completed because of a network related issue."
164+
case .smsRole:
165+
message = "SMS role related issue."
166+
case .emailRole:
167+
message = "Email role related issue."
168+
case .externalServiceException:
169+
message = "An external service like facebook/twitter threw an error."
170+
case .limitExceededException:
171+
message = "Limit exceeded exception. Thrown when the total number of user pools has exceeded a preset limit."
172+
case .resourceConflictException:
173+
message = "Thrown when a user tries to use a login which is already linked to another account."
174+
case .webAuthnChallengeNotFound:
175+
message = "The WebAuthn credentials don't match an existing request."
176+
case .webAuthnClientMismatch:
177+
message = "The client doesn't support WebAuhn authentication."
178+
case .webAuthnNotSupported:
179+
message = "WebAuthn is not supported on this device."
180+
case .webAuthnNotEnabled:
181+
message = "WebAuthn is not enabled."
182+
case .webAuthnOriginNotAllowed:
183+
message = "The device origin is not registered as an allowed origin."
184+
case .webAuthnRelyingPartyMismatch:
185+
message = "The relying party ID doesn't match."
186+
case .webAuthnConfigurationMissing:
187+
message = "The WebAuthn configuration is missing or incomplete."
188+
}
189+
return "\(String(describing: Self.self)).\(self): \(message)"
190+
}
191+
}

0 commit comments

Comments
 (0)