-
Notifications
You must be signed in to change notification settings - Fork 282
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
Add several error types #33
base: main
Are you sure you want to change the base?
Conversation
Adds the types JSONMarshalError, JSONUnmarshalError, HTTPRequestError, HTTPResposeError, and UnmarshalError. These errors represent the different steps in the GraphQL request where errors can occur. Change the Errors struct to be exported by the package. Add 'Path' and 'Type' fields to the Errors struct. The 'path' field is in the GraphQL specification. The 'type' field is not in the GraphQL specification. 'type' is returned by the GitHub V4 API.
Thanks for the PR. I'm going to need some time to review this and think about it. One challenge with making progress on this is that it locks in HTTP-specific types in this package, potentially making it harder to resolve #5. This may not be a big problem, as it's likely that would require a breaking API change anyway. Please feel free to ping me if I don't get back to this within a week. |
Bump on this. shurcooL/graphql will presumably support HTTP transports even with pluggable transports, so exposing a Currently you need to inspect the err.Error() string in the returned error to see if the error you got is due to a 403, which isn't that nice. |
Will this ever be done? Current errors handling is just plain unusable. |
Hey, Any chance of moving this forward? |
Co-authored-by: Nizar Malangadan <nizar-m@users.noreply.github.com>
This is a first attempt at implementing #31. Adds the types JSONMarshalError, JSONUnmarshalError, HTTPRequestError, HTTPResponseError, and UnmarshalError. These errors represent the different steps in the GraphQL request where errors can occur. Change the Errors struct to be exported by the package. Add 'Path' and 'Type' fields to the Errors struct. The 'path' field is in the GraphQL specification. The 'type' field is not in the GraphQL specification. 'type' is returned by the GitHub V4 API.
The implementation is a mixed success. The patch is providing me with some value. I can also see the argument that it has limited use. Here's how I use this new implementation in a GitHub service. For comparison I've also included the error handling logic for the GitHub V3 API:
The HTTPResponseError type might be useful except I haven't validated yet that the GitHub API returns anything except for a 200 response code. I haven't tried making a V4 API request with the wrong authentication token. That request may return a 400-something response.
When the GitHub V4 API returns a GraphQL error, currently it populates the non-standard field "type" to define the error type. The error types are not documented. Maybe they will eventually be documented: https://platform.github.community/t/document-error-handling/5387 ?