fix(GraphQL Node): Improve error handling (#6955)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Marcus 2023-08-18 11:22:12 +02:00 committed by GitHub
parent 60a1ef0993
commit 41db6371f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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({