donglun2024 2019-08-21 09:09
浏览 313
已采纳

当用户已经确认时,Cognito抛出ErrCodeNotAuthorizedException

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.

https://docs.aws.amazon.com/sdk-for-go/api/service/cognitoidentityprovider/#CognitoIdentityProvider.ConfirmSignUp

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.

  • 写回答

1条回答 默认 最新

  • douzhuang2570 2019-08-22 04:57
    关注

    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:          
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?