mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Respond to Webhook Node): Continue on fail and error branch support (#9115)
This commit is contained in:
parent
064e8f4a1d
commit
86a20f6563
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue