Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

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

authored by

Jovi De Croock and committed by
GitHub
a620d153 942eb161

+17 -2
+5
.changeset/good-walls-obey.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Allow empty error messages when re-hydrating GraphQL errors
+10
packages/core/src/utils/error.test.ts
··· 60 60 expect(err.graphQLErrors).toEqual(graphQLErrors); 61 61 }); 62 62 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 + 63 73 it('accepts a response that is attached to the resulting error', () => { 64 74 const response = {}; 65 75 const err = new CombinedError({
+2 -2
packages/core/src/utils/error.ts
··· 19 19 const rehydrateGraphQlError = (error: any): GraphQLError => { 20 20 if ( 21 21 error && 22 - error.message && 22 + typeof error.message === 'string' && 23 23 (error.extensions || error.name === 'GraphQLError') 24 24 ) { 25 25 return error; 26 - } else if (typeof error === 'object' && error.message) { 26 + } else if (typeof error === 'object' && typeof error.message === 'string') { 27 27 return new GraphQLError( 28 28 error.message, 29 29 error.nodes,