mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -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 { jsonParse, BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';
|
||||||
import set from 'lodash/set';
|
import set from 'lodash/set';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { formatPrivateKey } from '../../utils/utilities';
|
import { formatPrivateKey, generatePairedItemData } from '../../utils/utilities';
|
||||||
|
|
||||||
export class RespondToWebhook implements INodeType {
|
export class RespondToWebhook implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -287,8 +287,10 @@ export class RespondToWebhook implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
|
const items = this.getInputData();
|
||||||
const nodeVersion = this.getNode().typeVersion;
|
const nodeVersion = this.getNode().typeVersion;
|
||||||
|
|
||||||
|
try {
|
||||||
if (nodeVersion >= 1.1) {
|
if (nodeVersion >= 1.1) {
|
||||||
const connectedNodes = this.getParentNodes(this.getNode().name);
|
const connectedNodes = this.getParentNodes(this.getNode().name);
|
||||||
if (!connectedNodes.some((node) => node.type === 'n8n-nodes-base.webhook')) {
|
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 respondWith = this.getNodeParameter('respondWith', 0) as string;
|
||||||
const options = this.getNodeParameter('options', 0, {});
|
const options = this.getNodeParameter('options', 0, {});
|
||||||
|
@ -389,7 +390,10 @@ export class RespondToWebhook implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
const binaryKeys = Object.keys(item.binary);
|
const binaryKeys = Object.keys(item.binary);
|
||||||
if (binaryKeys.length === 0) {
|
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];
|
responseBinaryPropertyName = binaryKeys[0];
|
||||||
}
|
}
|
||||||
|
@ -422,6 +426,18 @@ export class RespondToWebhook implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sendResponse(response);
|
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];
|
return [items];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue