Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractProvider - unexpected, undocumented exceptions #880

Closed
lukaszmakuch opened this issue Mar 19, 2021 · 3 comments · Fixed by #1050
Closed

AbstractProvider - unexpected, undocumented exceptions #880

lukaszmakuch opened this issue Mar 19, 2021 · 3 comments · Fixed by #1050

Comments

@lukaszmakuch
Copy link

Hello! 👋

First of all, thank you for this project. It has saved me tons of time! 👍

I'm opening this issue to discuss the exceptions thrown by the AbstractProvider class.

When working with a provider, like the GenericProvider, I'd expect to catch some IdentityProviderExceptions. Its nicely documented:

* Exception thrown if the provider response contains errors.

However, much to my surprise, some methods such as getAccessToken or getResourceOwner may throw an UnexpectedValueException when there's something wrong with the response received from the Identity Provider. Sadly, this is not documented.

To be honest, I expected to catch nothing but IdentityProviderExceptions and my code broke because there was no catch block for UnexpectedValueExceptions.

What are your thoughts on this matter? 🤔 Should the fact that an UnexpectedValueException may be thrown be documented? Or maybe we can risk some breaking changes and modify the code to throw IdentityProviderExceptions instead of UnexpectedValueExceptions?

Cheers!

@cloudcogsio
Copy link

You can probably adjust your code to catch the different exceptions?

try {
    $accessToken = $provider->getAccessToken($grant, array $options = [])
} catch (IdentityProviderException $e) {
    // handle IdentityProviderException exceptions here
} catch (UnexpectedValueException $e) {
    // handle UnexpectedValueException  exceptions here
}

OR

try {
    $accessToken = $provider->getAccessToken($grant, array $options = [])
} catch (IdentityProviderException | UnexpectedValueException $e) {
    // handle IdentityProviderException and UnexpectedValueException exceptions here
} 

See: https://www.php.net/manual/en/language.exceptions.php#language.exceptions.catch

@lukaszmakuch
Copy link
Author

lukaszmakuch commented Aug 3, 2021 via email

@ramsey
Copy link
Contributor

ramsey commented Dec 22, 2021

Thanks for the suggestion, @lukaszmakuch. We'll keep this open until we've added appropriate @throws tags to all the docblocks. I hope that will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants