-
Notifications
You must be signed in to change notification settings - Fork 118
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 better error checking for fetched GraphQL requests #919
Conversation
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.
LGTM
} else if (jsonResponse.data === undefined) { | ||
return [ | ||
undefined, | ||
{ | ||
statusCode: response.status, | ||
statusText: `GraphQL response data is undefined`, |
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.
just double-checking -- are we sure that undefined
response data always means that the request failed?
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.
Good call. I believe this to be the case since we check that jsonResponse.data
exists when we try to do some processing on later functions:
- https://github.com/o1-labs/snarkyjs/blob/2fa164ef19ae2d24acb412a22e27f2e58ba71aec/src/lib/fetch.ts#L489
- https://github.com/o1-labs/snarkyjs/blob/2fa164ef19ae2d24acb412a22e27f2e58ba71aec/src/lib/fetch.ts#L635
- https://github.com/o1-labs/snarkyjs/blob/2fa164ef19ae2d24acb412a22e27f2e58ba71aec/src/lib/fetch.ts#L840
- https://github.com/o1-labs/snarkyjs/blob/2fa164ef19ae2d24acb412a22e27f2e58ba71aec/src/lib/fetch.ts#L908
I'm not sure of a case where we would make a GraphQL request and expect the data to be undefined. Even if we make a GraphQL mutation instead of a query, we would probably want some data returned (e.g. an ID).
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.
Ok I guess we can look at our current queries to check that we always want something returned, and this is currently the case 👍🏻
…requests in snarkyjs
Description
This PR introduces enhanced error handling for GraphQL network requests within the
Fetch
module. Previously, if a GraphQL request failed, the error output would be presented asstatusText
in an array format. This made error reporting from the user's application less informative, as it logged[object Object]
. An example of this less descriptive error logging is as follows:This error as produced by building snarkyjs with an invalid GraphQL schema in the request for
fetchEvents
.With the enhancements made in this PR, the error reporting becomes more informative and user-friendly. The new error messages provide specific details about the issues at hand. An example of the improved error message is:
Testing
The improvements introduced in this PR have been verified using a local test script.