-
Notifications
You must be signed in to change notification settings - Fork 221
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
Handle response status codes #8
Comments
Will there be a situation where we get an invalid HTTP status code, and a descriptive error in the JSON body? I suppose we might need to handle a few different possibilities:
|
@kivutar Would you be able to you submit a failing test for what you expect here? |
Sorry matryer, it's been a while since the last time I used the library, and now I'm doing completely unrelated things. I don't know HTTP enough to reply about the status codes. But most of the graphql servers I have been working with were using 200 in 99% of the cases, when displaying errors or normal payload. And 500 or 404 when the server is buggy or not well configured. |
I think letting the client handle the Errors object in the response is probably the best way to go since you can still receive a partial response of data. The main issue here is that if a non-200 status code is returned, there's still an attempt to marshal data and that throws an error that's not clear "invalid character 'N' looking for beginning of value" as an example. From what I've read it seems reasonable to expect a 200 status code always and if we don't then there's an error from the server. In those cases, don't attempt to unmarshal and return an informative error with the status code in it. |
I went ahead and submitted a PR @matryer I hope that was ok. I'm also open to any other approaches you'd like to suggest, but it seemed a like a clean and simple way to maintain current functionality, but provide a more informative error if the client isn't able to parse JSON in the response. |
I think there should be something like
after
In case the server returns a 400 or a 500, the current code returns:
The text was updated successfully, but these errors were encountered: