-
Notifications
You must be signed in to change notification settings - Fork 1
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
Don't throw exception on status code 200, 201 and 204 #1
base: master
Are you sure you want to change the base?
Conversation
I don't know how to work around this exception except for changing the source file. Teamleader may also return 201 and 204, that doesn't mean it's a bad response. https://developer.teamleader.eu/#/introduction/general-principles/status-codes
Thanks for the PR! Are you actually getting errors in your application? It seems strange to me that the OAuth endpoint returns something else than a That being said, anything |
Thank you for your fast response. I apologize that I didn't return the courtesy. Yes, the authentication does always return 200. But, the thing is, is that I'm using league/oauth2-client to also make API requests. League even provides an example where they make a request to some fictitious resource. https://oauth2-client.thephpleague.com/usage/. So I thought that it's meant to be used in that way. I believed that it'd be easier to just use the working out of the box request/response system league provides, instead of curl. Why does If you want some resource; first, you make a request with If we look inside the So, I conclude that checkResponse is not only used to authenticate. Some servers return other than 200 on API requests. So there are only 2 solutions to this problem.
It's also possible that I understand it all wrong. Let me know if you think that I do. I hope this provides an adequate elaboration of the problem. |
I believe your understanding is correct. We haven't encountered this issue ourselves because we do not use Your way of working with the provider is completely valid as well, so yes, we should absolutely check for successful status codes other than I think only checking for 200, 201, and 204 might not be enough though. The API docs use the words "Common used status codes", which implies they might use other ones as well. It'll probably be safer to treat all If you adjust your PR to do a similar success check I'll be more than happy to merge it! |
I was about to push something like this: But before I committed I wanted to see what other providers did (which both of us should have done way earlier). Examples of other prominent providers: I believe it's meant to check if the response is erroneous based protocols in the body, not just the status code from the headers. So I guess more research is needed since it's not as simple as: "is it status 200 or not". I can take a look at it if you still want me to. |
Good point. I think we went with the 200 check because the Teamleader API docs do not explicitly mention what is returned in the event of an error in the authentication flow. The providers you linked all check for the Let us know if you find something else, but I believe it's safe to take this approach. And thank you for thorough research! |
I don't know how to work around this exception except for changing the source file.
Teamleader may also return 201 and 204. It doesn't mean it's a bad response.
https://developer.teamleader.eu/#/introduction/general-principles/status-codes