mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-28 14:12:24 -05:00
Handle errors from example node and clarified options about credentials and properties
This commit is contained in:
parent
e2b4595066
commit
abe033d7a1
3 changed files with 38 additions and 30 deletions
|
|
@ -28,6 +28,10 @@ export class ExampleNode implements INodeType {
|
|||
],
|
||||
};
|
||||
|
||||
// The function below is responsible for actually doing whatever this node
|
||||
// is supposed to do. In this case, we're just appending the `myString` property
|
||||
// with whatever the user has entered.
|
||||
// You can make async calls and use `await`.
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
|
|
@ -38,10 +42,24 @@ export class ExampleNode implements INodeType {
|
|||
// value the parameter "myString" resolves to.
|
||||
// (This could be a different value for each item in case it contains an expression)
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
myString = this.getNodeParameter('myString', itemIndex, '') as string;
|
||||
item = items[itemIndex];
|
||||
try {
|
||||
myString = this.getNodeParameter('myString', itemIndex, '') as string;
|
||||
item = items[itemIndex];
|
||||
|
||||
item.json['myString'] = myString;
|
||||
} catch (error) {
|
||||
|
||||
// This node should never fail but we want to showcase how
|
||||
// to handle errors.
|
||||
if (this.continueOnFail()) {
|
||||
items.push({json: this.getInputData(itemIndex)[0].json, error});
|
||||
} else {
|
||||
// Adding `itemIndex` allows other workflows to handle this error
|
||||
if (error.context) error.context.itemIndex = itemIndex;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
item.json['myString'] = myString;
|
||||
}
|
||||
|
||||
return this.prepareOutputData(items);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue