mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(n8n Form Trigger Node): Error if Respond to Webhook and respond node not in workflow (#9641)
This commit is contained in:
parent
6187cc5762
commit
b45f3dc9fb
|
@ -1,4 +1,9 @@
|
|||
import { jsonParse, type IDataObject, type IWebhookFunctions } from 'n8n-workflow';
|
||||
import {
|
||||
NodeOperationError,
|
||||
jsonParse,
|
||||
type IDataObject,
|
||||
type IWebhookFunctions,
|
||||
} from 'n8n-workflow';
|
||||
import type { FormField, FormTriggerData, FormTriggerInput } from './interfaces';
|
||||
|
||||
export const prepareFormData = (
|
||||
|
@ -77,11 +82,44 @@ export const prepareFormData = (
|
|||
return formData;
|
||||
};
|
||||
|
||||
const checkResponseModeConfiguration = (context: IWebhookFunctions) => {
|
||||
const responseMode = context.getNodeParameter('responseMode', 'onReceived') as string;
|
||||
const connectedNodes = context.getChildNodes(context.getNode().name);
|
||||
|
||||
const isRespondToWebhookConnected = connectedNodes.some(
|
||||
(node) => node.type === 'n8n-nodes-base.respondToWebhook',
|
||||
);
|
||||
|
||||
if (!isRespondToWebhookConnected && responseMode === 'responseNode') {
|
||||
throw new NodeOperationError(
|
||||
context.getNode(),
|
||||
new Error('No Respond to Webhook node found in the workflow'),
|
||||
{
|
||||
description:
|
||||
'Insert a Respond to Webhook node to your workflow to respond to the form submission or choose another option for the “Respond When” parameter',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (isRespondToWebhookConnected && responseMode !== 'responseNode') {
|
||||
throw new NodeOperationError(
|
||||
context.getNode(),
|
||||
new Error(`${context.getNode().name} node not correctly configured`),
|
||||
{
|
||||
description:
|
||||
'Set the “Respond When” parameter to “Using Respond to Webhook Node” or remove the Respond to Webhook node',
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export async function formWebhook(context: IWebhookFunctions) {
|
||||
const mode = context.getMode() === 'manual' ? 'test' : 'production';
|
||||
const formFields = context.getNodeParameter('formFields.values', []) as FormField[];
|
||||
const method = context.getRequestObject().method;
|
||||
|
||||
checkResponseModeConfiguration(context);
|
||||
|
||||
//Show the form on GET request
|
||||
if (method === 'GET') {
|
||||
const formTitle = context.getNodeParameter('formTitle', '') as string;
|
||||
|
|
Loading…
Reference in a new issue