Skip to content

Commit 8bf2610

Browse files
authored
fix(auth): handle tooManyRequests and limitExceeded separately in AuthErrorHelper (#1122)
* fix(auth): handle tooManyRequests and limitExceeded separately in AuthErrorHelper * fix(auth): modify unit tests for AuthErrorHelper * fix(auth): resolve review comments Co-authored-by: Abhash Kumar Singh <[email protected]>
1 parent 0033079 commit 8bf2610

10 files changed

+33
-25
lines changed

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Models/Error/AWSCognitoAuthError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public enum AWSCognitoAuthError: Error {
3434
/// Password given is invalid.
3535
case invalidPassword
3636

37-
/// Number of allowed operation have exceeded.
37+
/// Limit exceeded for the requested AWS resource
3838
case limitExceeded
3939

4040
/// Amazon Cognito cannot find a multi-factor authentication (MFA) method.

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ extension AuthPluginErrorConstants {
229229
static let tooManyFailedError: RecoverySuggestion = "User might have tried too many times with failed input"
230230

231231
static let tooManyRequestError: RecoverySuggestion = """
232-
Make sure the requests send are controlled and the errors are properlly handled
232+
Make sure the requests send are controlled and the errors are properly handled
233+
"""
234+
235+
static let limitExceededError: RecoverySuggestion = """
236+
Make sure that the request made to the particular AWS resources are under the resource quota limits
233237
"""
234238

235239
static let configurationError: RecoverySuggestion = """

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Support/Utils/AuthErrorHelper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ struct AuthErrorHelper {
9999
AuthPluginErrorConstants.tooManyFailedError,
100100
AWSCognitoAuthError.failedAttemptsLimitExceeded)
101101

102-
case .tooManyRequests(let message),
103-
.limitExceeded(let message):
102+
case .tooManyRequests(let message):
104103
return AuthError.service(message,
105104
AuthPluginErrorConstants.tooManyRequestError,
106105
AWSCognitoAuthError.requestLimitExceeded)
107106

107+
case .limitExceeded(let message):
108+
return AuthError.service(message,
109+
AuthPluginErrorConstants.limitExceededError,
110+
AWSCognitoAuthError.limitExceeded)
111+
108112
case .errorLoadingPage(let message):
109113
return AuthError.service(message,
110114
AuthPluginErrorConstants.errorLoadingPageError,

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthUserBehaviorTests/UserBehaviorChangePasswordTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class UserBehaviorChangePasswordTests: BaseUserBehaviorTest {
149149
/// - When:
150150
/// - I invoke changePassword with old password and new password
151151
/// - Then:
152-
/// - I should get a .requestLimitExceeded error
152+
/// - I should get a .limitExceeded error
153153
///
154154
func testChangePasswordWithLimitExceededException() {
155155

@@ -168,8 +168,8 @@ class UserBehaviorChangePasswordTests: BaseUserBehaviorTest {
168168
XCTFail("Should produce service error instead of \(error)")
169169
return
170170
}
171-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
172-
XCTFail("Underlying error should be requestLimitExceeded \(error)")
171+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
172+
XCTFail("Underlying error should be limitExceeded \(error)")
173173
return
174174
}
175175
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthUserBehaviorTests/UserBehaviorConfirmAttributeTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class UserBehaviorConfirmAttributeTests: BaseUserBehaviorTest {
190190
/// - When:
191191
/// - I invoke confirmUpdateUserAttributes with confirmation code
192192
/// - Then:
193-
/// - I should get a .requestLimitExceeded error
193+
/// - I should get a .limitExceeded error
194194
///
195195
func testConfirmUpdateUserAttributesWithLimitExceededException() {
196196

@@ -210,8 +210,8 @@ class UserBehaviorConfirmAttributeTests: BaseUserBehaviorTest {
210210
XCTFail("Should produce service error instead of \(error)")
211211
return
212212
}
213-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
214-
XCTFail("Underlying error should be requestLimitExceeded \(error)")
213+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
214+
XCTFail("Underlying error should be limitExceeded \(error)")
215215
return
216216
}
217217
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthUserBehaviorTests/UserBehaviorResendCodeTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class UserBehaviorResendCodeTests: BaseUserBehaviorTest {
229229
/// - When:
230230
/// - I invoke resendConfirmationCode
231231
/// - Then:
232-
/// - I should get a .service error with .requestLimitExceeded as underlyingError
232+
/// - I should get a .service error with .limitExceeded as underlyingError
233233
///
234234
func testResendConfirmationCodeWithLimitExceededException() {
235235

@@ -249,8 +249,8 @@ class UserBehaviorResendCodeTests: BaseUserBehaviorTest {
249249
XCTFail("Should produce service error instead of \(error)")
250250
return
251251
}
252-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
253-
XCTFail("Underlying error should be requestLimitExceeded \(error)")
252+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
253+
XCTFail("Underlying error should be limitExceeded \(error)")
254254
return
255255
}
256256

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderConfirmResetPasswordTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class AuthenticationProviderConfirmResetPasswordTests: BaseAuthenticationProvide
352352
/// - When:
353353
/// - I invoke confirmResetPassword with a valid username, a new password and a confirmation code
354354
/// - Then:
355-
/// - I should get a .requestLimitExceeded error
355+
/// - I should get a .limitExceeded error
356356
///
357357
func testConfirmResetPasswordWithLimitExceededException() {
358358

@@ -374,8 +374,8 @@ class AuthenticationProviderConfirmResetPasswordTests: BaseAuthenticationProvide
374374
XCTFail("Should produce service error instead of \(error)")
375375
return
376376
}
377-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
378-
XCTFail("Underlying error should be resourceNotFound \(error)")
377+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
378+
XCTFail("Underlying error should be limitExceeded \(error)")
379379
return
380380
}
381381
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderConfirmSignupTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class AuthenticationProviderConfirmSignupTests: BaseAuthenticationProviderTest {
353353
/// - When:
354354
/// - I invoke confirmSignup with a valid username and confirmationCode
355355
/// - Then:
356-
/// - I should get a .requestLimitExceeded error
356+
/// - I should get a .limitExceeded error
357357
///
358358
func testConfirmSignUpWithLimitExceededException() {
359359

@@ -374,8 +374,8 @@ class AuthenticationProviderConfirmSignupTests: BaseAuthenticationProviderTest {
374374
XCTFail("Should produce service error instead of \(error)")
375375
return
376376
}
377-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
378-
XCTFail("Underlying error should be resourceNotFound \(error)")
377+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
378+
XCTFail("Underlying error should be limitExceeded \(error)")
379379
return
380380
}
381381
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderResendSignupCodeTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class AuthenticationProviderResendSignupCodeTests: BaseAuthenticationProviderTes
309309
/// - When:
310310
/// - I invoke resendSignUpCode with a valid username
311311
/// - Then:
312-
/// - I should get a .requestLimitExceeded error
312+
/// - I should get a .limitExceeded error
313313
///
314314
func testResendSignupCodeWithLimitExceededException() {
315315

@@ -329,8 +329,8 @@ class AuthenticationProviderResendSignupCodeTests: BaseAuthenticationProviderTes
329329
XCTFail("Should produce service error instead of \(error)")
330330
return
331331
}
332-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
333-
XCTFail("Underlying error should be resourceNotFound \(error)")
332+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
333+
XCTFail("Underlying error should be limitExceeded \(error)")
334334
return
335335
}
336336
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderResetPasswordTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class AuthenticationProviderResetPasswordTests: BaseAuthenticationProviderTest {
303303
/// - When:
304304
/// - I invoke resetPassword with username
305305
/// - Then:
306-
/// - I should get a .requestLimitExceeded error
306+
/// - I should get a .limitExceeded error
307307
///
308308
func testResetPasswordWithLimitExceededException() {
309309

@@ -323,8 +323,8 @@ class AuthenticationProviderResetPasswordTests: BaseAuthenticationProviderTest {
323323
XCTFail("Should produce service error instead of \(error)")
324324
return
325325
}
326-
guard case .requestLimitExceeded = (underlyingError as? AWSCognitoAuthError) else {
327-
XCTFail("Underlying error should be requestLimitExceeded \(error)")
326+
guard case .limitExceeded = (underlyingError as? AWSCognitoAuthError) else {
327+
XCTFail("Underlying error should be limitExceeded \(error)")
328328
return
329329
}
330330
}

0 commit comments

Comments
 (0)