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

fix(core): Allow for empty error messages when rehydrating #3650

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/good-walls-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Allow empty error messages when re-hydrating GraphQL errors
10 changes: 10 additions & 0 deletions packages/core/src/utils/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ describe('CombinedError', () => {
expect(err.graphQLErrors).toEqual(graphQLErrors);
});

it('accepts empty string errors for graphQLError', () => {
const graphQLErrors = [new Error('')];

const err = new CombinedError({ graphQLErrors });

expect(err.message).toBe('[GraphQL] ');

expect(err.graphQLErrors).toEqual(graphQLErrors);
});

it('accepts a response that is attached to the resulting error', () => {
const response = {};
const err = new CombinedError({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const generateErrorMessage = (
const rehydrateGraphQlError = (error: any): GraphQLError => {
if (
error &&
error.message &&
typeof error.message === 'string' &&
(error.extensions || error.name === 'GraphQLError')
) {
return error;
} else if (typeof error === 'object' && error.message) {
} else if (typeof error === 'object' && typeof error.message === 'string') {
return new GraphQLError(
error.message,
error.nodes,
Expand Down