Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GraphQL Node): Improve error handling #6955

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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