Skip to content

Commit

Permalink
Parse out error message to request users to format with JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dana-gill committed Jan 15, 2025
1 parent df6a17e commit 2bc02b3
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions packages/nodes-base/nodes/GraphQL/GraphQL.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2bc02b3

Please sign in to comment.