mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-28 14:12:24 -05:00
Add correct error output with context
This commit is contained in:
parent
abe033d7a1
commit
ba83500857
1 changed files with 8 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
import { INodeExecutionData, INodeType, INodeTypeDescription, NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
export class ExampleNode implements INodeType {
|
export class ExampleNode implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
|
@ -55,8 +55,13 @@ export class ExampleNode implements INodeType {
|
||||||
items.push({json: this.getInputData(itemIndex)[0].json, error});
|
items.push({json: this.getInputData(itemIndex)[0].json, error});
|
||||||
} else {
|
} else {
|
||||||
// Adding `itemIndex` allows other workflows to handle this error
|
// Adding `itemIndex` allows other workflows to handle this error
|
||||||
if (error.context) error.context.itemIndex = itemIndex;
|
if (error.context) {
|
||||||
throw error;
|
error.context.itemIndex = itemIndex;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
throw new NodeOperationError(this.getNode(), error.message, {
|
||||||
|
itemIndex,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue