diff --git a/src/components/GraphiQL.js b/src/components/GraphiQL.js index 2250be06db0..1c8bfbad39a 100644 --- a/src/components/GraphiQL.js +++ b/src/components/GraphiQL.js @@ -574,7 +574,7 @@ export class GraphiQL extends React.Component { error: error => { this.setState({ isWaitingForResponse: false, - response: error && String(error.stack || error), + response: this.makeSubscriptionErrorResponse(error), subscription: null, }); }, @@ -592,6 +592,18 @@ export class GraphiQL extends React.Component { } } + makeSubscriptionErrorResponse = error => { + const errorResp = { + errors: [], + }; + if (error.originalError) { + errorResp.errors.push(error.originalError); + } else { + errorResp.errors.push(error); + } + return JSON.stringify(errorResp, null, 2); + }; + handleClickReference = reference => { this.setState({ docExplorerOpen: true }, () => { this.docExplorerComponent.showDocForReference(reference); @@ -642,7 +654,9 @@ export class GraphiQL extends React.Component { } catch (error) { this.setState({ isWaitingForResponse: false, - response: error.message, + response: error.message + ? JSON.stringify(error.message, null, 2) + : JSON.stringify(error, null, 2), }); } };