Skip to content

Commit a620d15

Browse files
authored
fix(core): Allow for empty error messages when rehydrating (#3650)
1 parent 942eb16 commit a620d15

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

.changeset/good-walls-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@urql/core': patch
3+
---
4+
5+
Allow empty error messages when re-hydrating GraphQL errors

packages/core/src/utils/error.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ describe('CombinedError', () => {
6060
expect(err.graphQLErrors).toEqual(graphQLErrors);
6161
});
6262

63+
it('accepts empty string errors for graphQLError', () => {
64+
const graphQLErrors = [new Error('')];
65+
66+
const err = new CombinedError({ graphQLErrors });
67+
68+
expect(err.message).toBe('[GraphQL] ');
69+
70+
expect(err.graphQLErrors).toEqual(graphQLErrors);
71+
});
72+
6373
it('accepts a response that is attached to the resulting error', () => {
6474
const response = {};
6575
const err = new CombinedError({

packages/core/src/utils/error.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const generateErrorMessage = (
1919
const rehydrateGraphQlError = (error: any): GraphQLError => {
2020
if (
2121
error &&
22-
error.message &&
22+
typeof error.message === 'string' &&
2323
(error.extensions || error.name === 'GraphQLError')
2424
) {
2525
return error;
26-
} else if (typeof error === 'object' && error.message) {
26+
} else if (typeof error === 'object' && typeof error.message === 'string') {
2727
return new GraphQLError(
2828
error.message,
2929
error.nodes,

0 commit comments

Comments
 (0)