fix(GraphQL Node)!: Correctly report errors returned by the API (#3071)

* upstream merge

*  graphql node will throw error when response has errors property

* 🔨 updated changelog

*  Improvements

*  Improvements

*  Add package-lock.json back

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
Michael Kret
2022-04-01 15:38:26 +03:00
committed by GitHub
parent 0b08be1c0b
commit 8a94f1e361
3 changed files with 45960 additions and 78 deletions

View File

@@ -4,6 +4,7 @@ import {
INodeExecutionData,
INodeType,
INodeTypeDescription,
JsonObject,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';
@@ -412,17 +413,22 @@ export class GraphQL implements INodeType {
} else {
if (typeof response === 'string') {
try {
returnItems.push({ json: JSON.parse(response) });
response = JSON.parse(response);
} catch (error) {
throw new NodeOperationError(this.getNode(), 'Response body is not valid JSON. Change "Response Format" to "String"');
}
} else {
returnItems.push({ json: response });
}
if (response.errors) {
const message = response.errors?.map((error: IDataObject) => error.message).join(', ') || 'Unexpected error';
throw new NodeApiError(this.getNode(), response.errors, { message });
}
returnItems.push({ json: response });
}
} catch (error) {
if (this.continueOnFail()) {
returnItems.push({ json: { error: error.message } });
returnItems.push({ json: { error: (error as JsonObject).message } });
continue;
}
throw error;