Skip to content
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

Merged
merged 3 commits into from
May 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,17 @@ async function checkResponseStatus(
undefined,
{
statusCode: response.status,
statusText: jsonResponse.errors,
statusText: jsonResponse.errors
.map((error: any) => error.message)
.join('\n'),
} as FetchError,
];
} else if (jsonResponse.data === undefined) {
return [
undefined,
{
statusCode: response.status,
statusText: `GraphQL response data is undefined`,
Comment on lines +1094 to +1099
Copy link
Member

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?

Copy link
Contributor Author

@MartinMinkov MartinMinkov May 23, 2023

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:

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).

Copy link
Member

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 👍🏻

} as FetchError,
];
}
Expand Down
Loading