Skip to content

Commit

Permalink
fix(core): Allow for empty error messages when rehydrating (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Aug 5, 2024
1 parent 942eb16 commit a620d15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit a620d15

Please sign in to comment.