Why does cognito throw ErrCodeNotAuthorizedException "NotAuthorizedException"
when the status of the user is already confirmed when making a request to cognito to confirm the user. The documentation specifies that ErrCodeNotAuthorizedException
is thrown when a user is not authorized.
How should we handle this case? As it would be unclear if we made a request with invalid client secret
as it would throw the same error.
Since the code is the same for the unauthorized case and user already confirmed case, the only possible way to differentiate the cases is to match the awsErr.Message()
which provides the clear description of the error.
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case cognitoidentityprovider.ErrCodeNotAuthorizedException:
if awsErr.Message() == "User cannot be confirm. Current status is CONFIRMED" {
log.Println("Handle user already confirmed")
} else {
log.Println("Handle not authorized case")
}
...
default:
}
}