From 41db6371f0d7a736bf7e1c13e2a3acd678bec246 Mon Sep 17 00:00:00 2001 From: Marcus <56945030+maspio@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:22:12 +0200 Subject: [PATCH] fix(GraphQL Node): Improve error handling (#6955) Github issue / Community forum post (link here to close automatically): --- .../nodes-base/nodes/GraphQL/GraphQL.node.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts index 4e5598d11bcb5..0f6f233cd979f 100644 --- a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts +++ b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts @@ -483,18 +483,29 @@ export class GraphQL implements INodeType { } } - if (response.errors) { - const message = - response.errors?.map((error: IDataObject) => error.message).join(', ') || - 'Unexpected error'; - throw new NodeApiError(this.getNode(), response.errors as JsonObject, { message }); - } const executionData = this.helpers.constructExecutionMetaData( this.helpers.returnJsonArray(response as IDataObject), { itemData: { item: itemIndex } }, ); returnItems.push(...executionData); } + + // parse error string messages + if (typeof response === 'string' && response.startsWith('{"errors":')) { + try { + const errorResponse = JSON.parse(response) as IDataObject; + if (Array.isArray(errorResponse.errors)) { + response = errorResponse; + } + } catch (e) {} + } + // throw from response object.errors[] + if (typeof response === 'object' && response.errors) { + const message = + response.errors?.map((error: IDataObject) => error.message).join(', ') || + 'Unexpected error'; + throw new NodeApiError(this.getNode(), response.errors as JsonObject, { message }); + } } catch (error) { if (this.continueOnFail()) { const errorData = this.helpers.returnJsonArray({