Skip to content

Commit

Permalink
fix(GraphQL Node): Improve error handling (#6955)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):
  • Loading branch information
maspio authored and netroy committed Aug 18, 2023
1 parent 81367cf commit e8937aa
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/nodes-base/nodes/GraphQL/GraphQL.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit e8937aa

Please sign in to comment.