How to proper handle NotAuthorizedException in AWS

Viewed 153

The AWS Cognito InitiateAuth can throw the NotAuthorizedException if something fails during login.

The problem that I'm facing is that the exception can be thrown by the client for multiple reasons:

  • wrong password
  • temporary password expired
  • etc

but it's seems that there's no specific exception thus the only way i see for properly handle this it's to check the returned message

{'Error': {'Code': 'NotAuthorizedException',
           'Message': 'Temporary password has expired and must be reset by an '
                      'administrator.'},
...

Is this the correct way? because it seems very shaky to test the Message string (that is supposed to be changed from the sdk for whatever reason since it's just a display message).

In the end i would like to being able to understand if the user just sent a wrong authentication data or if its temporary password password it's completely "broken" and should be resetted

0 Answers
Related