fix(Respond to Webhook Node): Continue on fail and error branch support (#9115)

This commit is contained in:
Michael Kret 2024-04-11 13:16:57 +03:00 committed by GitHub
parent 064e8f4a1d
commit 86a20f6563
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,7 @@ import type {
import { jsonParse, BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';
import set from 'lodash/set';
import jwt from 'jsonwebtoken';
import { formatPrivateKey } from '../../utils/utilities';
import { formatPrivateKey, generatePairedItemData } from '../../utils/utilities';
export class RespondToWebhook implements INodeType {
description: INodeTypeDescription = {
@ -287,8 +287,10 @@ export class RespondToWebhook implements INodeType {
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const nodeVersion = this.getNode().typeVersion;
try {
if (nodeVersion >= 1.1) {
const connectedNodes = this.getParentNodes(this.getNode().name);
if (!connectedNodes.some((node) => node.type === 'n8n-nodes-base.webhook')) {
@ -302,7 +304,6 @@ export class RespondToWebhook implements INodeType {
);
}
}
const items = this.getInputData();
const respondWith = this.getNodeParameter('respondWith', 0) as string;
const options = this.getNodeParameter('options', 0, {});
@ -389,7 +390,10 @@ export class RespondToWebhook implements INodeType {
} else {
const binaryKeys = Object.keys(item.binary);
if (binaryKeys.length === 0) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on the first item!');
throw new NodeOperationError(
this.getNode(),
'No binary data exists on the first item!',
);
}
responseBinaryPropertyName = binaryKeys[0];
}
@ -422,6 +426,18 @@ export class RespondToWebhook implements INodeType {
};
this.sendResponse(response);
} catch (error) {
if (this.continueOnFail()) {
const itemData = generatePairedItemData(items.length);
const returnData = this.helpers.constructExecutionMetaData(
[{ json: { error: error.message } }],
{ itemData },
);
return [returnData];
}
throw error;
}
return [items];
}