From e83c8e4be9eb7b4566a10498b271cc8daf5ca281 Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Wed, 11 Mar 2020 16:50:49 -0600 Subject: [PATCH] createRequestError: parse object messages to string Before, error objects would come out of absinthe sockets as `request [object Object]`. For example, these sort of GraphQL errors returned via socket: ``` { errors: [ { locations: [Array], message: 'Fragment spread has no type overlap with parent.\n' + 'Parent possible types: ["RootSubscriptionType"]\n' + 'Spread possible types: ["User"]\n' } ] } ``` Now, they'll show up as stringified JSON. --- packages/socket/src/pushRequestUsing.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/socket/src/pushRequestUsing.js b/packages/socket/src/pushRequestUsing.js index 9e5f12d8..0a8352fb 100644 --- a/packages/socket/src/pushRequestUsing.js +++ b/packages/socket/src/pushRequestUsing.js @@ -27,7 +27,14 @@ const setNotifierRequestStatusSending = (absintheSocket, notifier) => requestStatus: requestStatuses.sending }); -const createRequestError = message => new Error(`request: ${message}`); +const createRequestError = message => { + if (String(message) === '[object Object]') { + try { + message = JSON.stringify(message, null, 2); + } catch (_) {} + } + return new Error(`request: ${message}`) +}; const onTimeout = (absintheSocket, notifier) => notifierNotifyActive(