kamermans / guzzle-oauth2-subscriber

OAuth 2.0 Client for Guzzle 4, 5, 6 and 7 with PHP 5.4 - PHP 8.0 - no more dependency hell!
MIT License
140 stars 31 forks source link

Add upstream exception message to AccessTokenRequestException message #18

Closed davereid closed 2 years ago

davereid commented 5 years ago

If the access token response returns like a 401 error, it would be good to include the exception message from Guzzle back into the AccessTokenRequestException. For example, I wrote a custom GrantType that throws a custom BadResponseException (since our API returns its error messages inside the body of the response), but with this current code, that exception message is lost and only reported as "Unable to request a new access token" which isn't the most helpful in knowing why that request failed.

kamermans commented 5 years ago

Thanks for the contribution @davereid! I'm not opposed to adding this, but it's worth mentioning that I pass the original exception through, so you can access that message today like $e->getPrevious()->getMessage().