Skip to content

Commit

Permalink
Merge pull request #243 from Simperium/issue/242-handle-429-error
Browse files Browse the repository at this point in the history
Add error handling for too many login attempts error 429
  • Loading branch information
danilo04 authored Sep 30, 2021
2 parents 78e8200 + 4701682 commit 86ea7ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void run() {
case COMPROMISED_PASSWORD:
showCompromisedPasswordDialog();
break;
case TOO_MANY_REQUESTS:
showDialogError(getString(R.string.simperium_too_many_attempts));
break;
case INVALID_ACCOUNT:
default:
showDialogError(getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class AuthException extends SimperiumException {
static public final String EXISTING_USER_FAILURE_MESSAGE = "Account already exists";
static public final String UNVERIFIED_ACCOUNT_MESSAGE = "Account verification required";
static public final String COMPROMISED_PASSWORD_MESSAGE = "Password has been compromised";
static public final String TOO_MANY_REQUESTS_MESSAGE = "Too many log in attempts";

static public final String COMPROMISED_PASSWORD_BODY = "compromised password";
static public final String VERIFICATION_REQUIRED_BODY = "verification required";

Expand All @@ -18,7 +20,7 @@ public class AuthException extends SimperiumException {
public final FailureType failureType;

public enum FailureType {
INVALID_ACCOUNT, EXISTING_ACCOUNT, COMPROMISED_PASSWORD, UNVERIFIED_ACCOUNT
INVALID_ACCOUNT, EXISTING_ACCOUNT, COMPROMISED_PASSWORD, UNVERIFIED_ACCOUNT, TOO_MANY_REQUESTS
}

public AuthException(FailureType code, String message){
Expand All @@ -44,6 +46,8 @@ public static AuthException exceptionForStatusCode(int statusCode, Throwable cau

if (statusCode == 409) {
return new AuthException(FailureType.EXISTING_ACCOUNT, EXISTING_USER_FAILURE_MESSAGE, cause);
} else if (statusCode == 429) {
return new AuthException(FailureType.TOO_MANY_REQUESTS, TOO_MANY_REQUESTS_MESSAGE, cause);
} else if (statusCode == 403 && Objects.equals(message, VERIFICATION_REQUIRED_BODY)) {
return new AuthException(FailureType.UNVERIFIED_ACCOUNT, UNVERIFIED_ACCOUNT_MESSAGE, cause);
} else if (statusCode == 401 && Objects.equals(message, COMPROMISED_PASSWORD_BODY)) {
Expand Down
1 change: 1 addition & 0 deletions Simperium/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
<string name="simperium_account_verification">Account Verification Required</string>
<string name="simperium_account_verification_message">You must verify your email before logging in to your account.</string>
<string name="simperium_okay">Okay</string>
<string name="simperium_too_many_attempts">Too many log in attempts. Try again later.</string>
</resources>

0 comments on commit 86ea7ab

Please sign in to comment.