From 2bc02b35d559595976bb77870fd7e99bfa124411 Mon Sep 17 00:00:00 2001 From: Dana Lee Date: Wed, 15 Jan 2025 11:23:20 +0100 Subject: [PATCH] Parse out error message to request users to format with JSON --- .../nodes-base/nodes/GraphQL/GraphQL.node.ts | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts index b1b69f24e2cc9..29b5f597226d8 100644 --- a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts +++ b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts @@ -510,26 +510,21 @@ export class GraphQL implements INodeType { }, }); } else { - if (typeof response === 'string') { - try { - response = JSON.parse(response) as IDataObject; - if ( - response.errors && - Array.isArray(response.errors) && - requestFormat === 'graphql' - ) { - throw new NodeOperationError( - this.getNode(), - 'Error in GraphQL request. Please try using the Request format "JSON" instead.', - ); - } - } catch (error) { - throw new NodeOperationError( - this.getNode(), - 'Response body is not valid JSON. Change "Response Format" to "String"', - { itemIndex }, - ); - } + if ( + typeof response === 'string' && + (JSON.parse(response) as IDataObject).errorMessage && + requestFormat === 'graphql' + ) { + throw new NodeOperationError( + this.getNode(), + 'Error in GraphQL request. Please try using the Request format "JSON" instead.', + ); + } else { + throw new NodeOperationError( + this.getNode(), + 'Response body is not valid JSON. Change "Response Format" to "String"', + { itemIndex }, + ); } const executionData = this.helpers.constructExecutionMetaData(