Move options around and also allow no data for last node

This commit is contained in:
Jan Oberhauser
2022-02-19 12:37:41 +01:00
parent cb3f0a0ec6
commit ea1b627ab0
3 changed files with 67 additions and 50 deletions

View File

@@ -204,14 +204,15 @@ export async function executeWebhook(
200,
) as number;
if (
![
'onReceived',
'lastNode',
'responseNode',
'noBodyResponse'
].includes(responseMode as string)
) {
const responseData = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
additionalKeys,
'firstEntryJson',
);
if (!['onReceived', 'lastNode', 'responseNode'].includes(responseMode as string)) {
// If the mode is not known we error. Is probably best like that instead of using
// the default that people know as early as possible (probably already testing phase)
// that something does not resolve properly.
@@ -338,7 +339,12 @@ export async function executeWebhook(
// directly if responseMode it set to "onReceived" and a respone should be sent
if (responseMode === 'onReceived' && !didSendResponse) {
// Return response directly and do not wait for the workflow to finish
if (webhookResultData.webhookResponse !== undefined) {
if (responseData === 'noData') {
// Return without data
responseCallback(null, {
responseCode,
});
} else if (webhookResultData.webhookResponse !== undefined) {
// Data to respond with is given
responseCallback(null, {
data: webhookResultData.webhookResponse,
@@ -356,17 +362,6 @@ export async function executeWebhook(
didSendResponse = true;
}
// Some systems require that a webhook doesn't respond with any data
// if responseMode is set to noBodyResponse we will see this fire
if (responseMode === 'noBodyResponse' && !didSendResponse) {
// Return response without data
responseCallback(null, {
responseCode,
});
didSendResponse = true;
}
// Initialize the data of the webhook node
const nodeExecutionStack: IExecuteData[] = [];
nodeExecutionStack.push({
@@ -526,16 +521,8 @@ export async function executeWebhook(
$executionId: executionId,
};
const responseData = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
additionalKeys,
'firstEntryJson',
);
if (!didSendResponse) {
let data: IDataObject | IDataObject[];
let data: IDataObject | IDataObject[] | undefined;
if (responseData === 'firstEntryJson') {
// Return the JSON data of the first entry
@@ -639,6 +626,9 @@ export async function executeWebhook(
noWebhookResponse: true,
});
}
} else if (responseData === 'noData') {
// Return without data
data = undefined;
} else {
// Return the JSON data of all the entries
data = [];