-
Notifications
You must be signed in to change notification settings - Fork 283
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
Report more details about errors in do function #24
base: main
Are you sure you want to change the base?
Conversation
Move status code control to the end of the 'do' function, so we can return more details about the error.
graphql.go
Outdated
return err | ||
respBodyCopy, errRead := ioutil.ReadAll(resp.Body) | ||
if errRead != nil { | ||
fmt.Errorf("error decoding output: <an additional error ocurred while reading output: %s>", errRead) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
staticcheck: Errorf is a pure function but its return value is ignored (SA4017)
graphql.go
Outdated
if resp.StatusCode != http.StatusOK { | ||
respBodyCopy, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
fmt.Errorf("unexpected status: %v <an additional error ocurred while reading output: %s>", resp.Status, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
staticcheck: Errorf is a pure function but its return value is ignored (SA4017)
Hi, thanks for the PR. I'd like to understand this better, so we can implement a better solution. Can you tell me under what conditions a non-200 response code is expected from a GraphQL server? How can I reproduce this? |
Hi!
For instance, when you execute a request with wrong graphql arguments it
retrieves 400 response, and it is difficult to understand which is the
problem. It could be either bad argument name, extra variables non-used or
another query mistake.
It makes hard/slow to implement queries. Graphiql returns real errors, so
the developer can figure out which is his mistake faster.
Does it make sense?
Thanks,
Jorge
2018-07-03 20:24 GMT+02:00 Dmitri Shuralyov <[email protected]>:
… Hi, thanks for the PR. I'd like to understand it better, so we can
implement a better solution.
Can you tell me under what conditions a non-200 response code is expected
from a GraphQL server? How can I reproduce this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABDM3r6RbsdQ09ljvUTxt9V_2N9PNJgXks5uC7b0gaJpZM4U2dpE>
.
--
**-* Jorge Sevilla Cedillo *-**
|
Hey all, A graphql server can return a 4xx error. As an HTTP server, if the error is found to be on the client side, it must return a 4xx error. For instance, the postgraphile project has several 4xx status codes. https://github.com/graphile/postgraphile/search?q=400&unscoped_q=400 |
Some news about merging this PR? It will be so useful for us, since we used the library in production and this change can help us to debug errors. Thanks in advance, |
There are a few reasons I can't merge this PR yet:
I'll need to think more about how to best handle these issues. If you need custom behavior for your specific use case, I suggest using a modified version of this library until we come up with a satisfactory general solution. |
Thanks, @dmitshur We will continue using your wonderful library and perhaps we will maintain a light fork with the improved error reporting. Let us know if you need with something. Thanks again. |
Coming here from #29...
Currently only status code 200 is accepted and this PR doesn't change that so this PR isn't really related to which status codes should be handled.
Agreed, that sounds super useful, but I think the vast majority of users of the library would like the response body text from error responses to be exposed in error messages for error responses and it shouldn't be the case that most users need to write their own transport layer just to get a more descriptive error message.
As above, I think this is orthogonal to this PR since this PR doesn't modify which status codes should be considered errors, but rather includes the response body for whatever status codes we consider to be errors as part of the error message. I definitely agree with the correctness problems, but those are easy to resolve once there is consensus on the direction of the PR. |
@jorgesece and @robermorales, I've merged PR #30, which should help. Please let me know if it works for your needs, or if doesn't completely cover them. |
I commented on #30. |
* Allow tagging of the field as having a scalar GraphQL type This change allows us to specify that a field in a struct has a scalar GraphQL type associated with it. This is done by adding the tag `scalar:"true"` to the field. This would allow us to - Avoid expansion of the field during request query generation, even when the golang type of the field is a struct - When the response is decoded, the value is simply JSON decoded, instead of the much stricter GraphQL decode. - Types like map[string]interface{}, json.RawMessage, etc should work as far as the corresponding fields are marked as scalar * Handle the error message where we are decoding as json.rawMessage Co-authored-by: Nizar Malangadan <[email protected]>
Move status code control to the end of the 'do' function, so we can return more details about the error.