pmill / aws-cognito

A PHP library for AWS Cognito user pools
MIT License
74 stars 62 forks source link

Uncaught Exception #26

Open fstiehle opened 5 years ago

fstiehle commented 5 years ago

The AWS SDK, in addition to CognitoIdentityProviderException seems to also throw GuzzleHttp\Exception\ClientException.

public function registerUser() for example throws this for {"__type":"UsernameExistsException","message":"User already exists"} (See error snippet below).

This doesn't get caught and mapped to the pmill\AwsCognito\Exception's. Making the error handling significantly harder for the caller method.

(Related #20?)

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://cognito-idp.us-east-1.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"UsernameExistsException","message":"User already exists"} in /app/public/.../vendor/pmill/aws-cognito/src/Exception/CognitoResponseException.php on line 28

alielephant commented 5 years ago

Facing the same issue, I cant catch the exception. CognitoClient Class need to return the issue instead of throwing an exception : throw CognitoResponseException::createFromCognitoException($e);

pmill commented 5 years ago

I'd be happy to accept a pull request for this.