mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user