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)

Changed files
+17 -2
.changeset
packages
core
+5
.changeset/good-walls-obey.md
···
+
---
+
'@urql/core': patch
+
---
+
+
Allow empty error messages when re-hydrating GraphQL errors
+10
packages/core/src/utils/error.test.ts
···
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({
+2 -2
packages/core/src/utils/error.ts
···
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,