Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): throw correct auth exception for code mismatch #1370

Merged
merged 13 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,8 @@ public void onResult(ForgotPasswordResult result) {

@Override
public void onError(Exception error) {
onException.accept(new AuthException(
"An error occurred confirming password recovery code",
error,
"See attached exception for more details"
));
onException.accept(CognitoAuthExceptionConverter.lookup(
error, "Confirm reset password failed."));
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException;
import com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException;
import com.amazonaws.services.cognitoidentityprovider.model.UsernameExistsException;
import com.amazonaws.services.cognitoidentityprovider.model.MFAMethodNotFoundException;

/**
* Convert AWS Cognito Exceptions to AuthExceptions.
Expand Down Expand Up @@ -91,6 +92,10 @@ public static AuthException lookup(@NonNull Exception error, @NonNull String fal
return new AuthException.LimitExceededException(error);
}

if (error instanceof MFAMethodNotFoundException) {
return new AuthException.MFAMethodNotFoundException(error);
}

if (error instanceof ResourceNotFoundException) {
return new AuthException.ResourceNotFoundException(error);
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/com/amplifyframework/auth/AuthException.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ public LimitExceededException(Throwable cause) {
}
}

/**
* Could not find multi-factor authentication (MFA) method in AWS Cognito.
*/
public static class MFAMethodNotFoundException extends AuthException {
private static final long serialVersionUID = 1L;
private static final String MESSAGE = "Could not find multi-factor authentication (MFA) method.";
private static final String RECOVERY_SUGGESTION = "Configure multi-factor authentication using Amplify CLI or AWS Cognito console.";

/**
* Default message/recovery suggestion with a cause.
* @param cause The original error.
*/
public MFAMethodNotFoundException(Throwable cause) {
super(MESSAGE, cause, RECOVERY_SUGGESTION);
}
}

/**
* Could not perform the action because password needs to be reset.
*/
Expand Down