mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
fix(GraphQL Node): Improve error handling (#6955)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
parent
60a1ef0993
commit
41db6371f0
|
@ -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({
|
||||
|
|
Loading…
Reference in a new issue