n8n/packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.ts

68 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-06-23 03:35:23 -07:00
import { IExecuteFunctions } from 'n8n-core';
import {
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
export class ErrorTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Error Trigger',
name: 'errorTrigger',
icon: 'fa:bug',
group: ['trigger'],
version: 1,
description: 'Triggers the workflow when another workflow has an error',
eventTriggerDescription: '',
2019-06-23 03:35:23 -07:00
maxNodes: 1,
defaults: {
name: 'Error Trigger',
color: '#0000FF',
},
inputs: [],
outputs: ['main'],
2020-10-22 06:46:03 -07:00
properties: [],
2019-06-23 03:35:23 -07:00
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const mode = this.getMode();
if (mode === 'manual' && items.length === 1 && Object.keys(items[0].json).length === 0 && items[0].binary === undefined) {
// If we are in manual mode and no input data got provided we return
// example data to allow to develope and test errorWorkflows easily
const restApiUrl = this.getRestApiUrl();
const urlParts = restApiUrl.split('/');
urlParts.pop();
urlParts.push('execution');
const id = 231;
2019-06-23 03:35:23 -07:00
items[0].json = {
execution: {
id,
url: `${urlParts.join('/')}/${id}`,
retryOf: '34',
2019-06-23 03:35:23 -07:00
error: {
message: 'Example Error Message',
2020-10-22 06:46:03 -07:00
stack: 'Stacktrace',
2019-06-23 03:35:23 -07:00
},
lastNodeExecuted: 'Node With Error',
2020-10-22 06:46:03 -07:00
mode: 'manual',
2019-06-23 03:35:23 -07:00
},
workflow: {
id: '1',
2020-10-22 06:46:03 -07:00
name: 'Example Workflow',
},
2019-06-23 03:35:23 -07:00
};
}
return this.prepareOutputData(items);
}
}