From 76e8b66cc9739349b0dd014a4776459f8c7a823e Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Wed, 24 Jan 2018 16:09:11 +0100 Subject: [PATCH] Fix error messages for non-Chrome browsers. (#1568) Check if error.stack contains error.message, and if not, append it to the error message printed to the console. This should fix error messages in Firefox and Safari. --- src/graphql.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/graphql.tsx b/src/graphql.tsx index d5a7009479..2ef4f9d8c5 100644 --- a/src/graphql.tsx +++ b/src/graphql.tsx @@ -564,9 +564,16 @@ export default function graphql< // _feel_ like it was logged ASAP while still tolerating asynchrony. let logErrorTimeoutId = setTimeout(() => { if (error) { + let errorMessage = error; + if (error.stack) { + errorMessage = error.stack.includes(error.message) + ? error.stack + : `${error.message}\n${error.stack}`; + } + console.error( `Unhandled (in react-apollo:${graphQLDisplayName})`, - error.stack || error, + errorMessage, ); } }, 10);