mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Fix issue with thrown errors for nodes with multiple webhooks
This commit is contained in:
parent
717708d3cc
commit
b171cfbb10
|
@ -258,17 +258,20 @@ export class ActiveWorkflowRunner {
|
||||||
await Db.collections.Webhook?.insert(webhook);
|
await Db.collections.Webhook?.insert(webhook);
|
||||||
|
|
||||||
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, false);
|
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, false);
|
||||||
if (webhookExists === false) {
|
if (webhookExists !== true) {
|
||||||
// If webhook does not exist yet create it
|
// If webhook does not exist yet create it
|
||||||
await workflow.runWebhookMethod('create', webhookData, NodeExecuteFunctions, mode, false);
|
await workflow.runWebhookMethod('create', webhookData, NodeExecuteFunctions, mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
await this.removeWorkflowWebhooks(workflow.id as string);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Could not remove webhooks of workflow "${workflow.id}" because of error: "${error.message}"`);
|
||||||
|
}
|
||||||
|
|
||||||
let errorMessage = '';
|
let errorMessage = '';
|
||||||
|
|
||||||
await Db.collections.Webhook?.delete({ workflowId: workflow.id });
|
|
||||||
|
|
||||||
// if it's a workflow from the the insert
|
// if it's a workflow from the the insert
|
||||||
// TODO check if there is standard error code for deplicate key violation that works
|
// TODO check if there is standard error code for deplicate key violation that works
|
||||||
// with all databases
|
// with all databases
|
||||||
|
|
|
@ -156,9 +156,12 @@ export class TestWebhooks {
|
||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
let key: string;
|
let key: string;
|
||||||
|
const activatedKey: string[] = [];
|
||||||
for (const webhookData of webhooks) {
|
for (const webhookData of webhooks) {
|
||||||
key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
|
key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
|
||||||
|
|
||||||
|
activatedKey.push(key);
|
||||||
|
|
||||||
this.testWebhookData[key] = {
|
this.testWebhookData[key] = {
|
||||||
sessionId,
|
sessionId,
|
||||||
timeout,
|
timeout,
|
||||||
|
@ -166,7 +169,13 @@ export class TestWebhooks {
|
||||||
workflowData,
|
workflowData,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.activeWebhooks!.add(workflow, webhookData, mode);
|
try {
|
||||||
|
await this.activeWebhooks!.add(workflow, webhookData, mode);
|
||||||
|
} catch (error) {
|
||||||
|
activatedKey.forEach(deleteKey => delete this.testWebhookData[deleteKey] );
|
||||||
|
await this.activeWebhooks!.removeWorkflow(workflow);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -189,8 +198,6 @@ export class TestWebhooks {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foundWebhook = true;
|
|
||||||
|
|
||||||
clearTimeout(this.testWebhookData[webhookKey].timeout);
|
clearTimeout(this.testWebhookData[webhookKey].timeout);
|
||||||
|
|
||||||
// Inform editor-ui that webhook got received
|
// Inform editor-ui that webhook got received
|
||||||
|
@ -207,7 +214,13 @@ export class TestWebhooks {
|
||||||
|
|
||||||
// Remove the webhook
|
// Remove the webhook
|
||||||
delete this.testWebhookData[webhookKey];
|
delete this.testWebhookData[webhookKey];
|
||||||
this.activeWebhooks!.removeWorkflow(workflow);
|
|
||||||
|
if (foundWebhook === false) {
|
||||||
|
// As it removes all webhooks of the workflow execute only once
|
||||||
|
this.activeWebhooks!.removeWorkflow(workflow);
|
||||||
|
}
|
||||||
|
|
||||||
|
foundWebhook = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundWebhook;
|
return foundWebhook;
|
||||||
|
|
|
@ -52,7 +52,7 @@ export class ActiveWebhooks {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
|
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
|
||||||
if (webhookExists === false) {
|
if (webhookExists !== true) {
|
||||||
// If webhook does not exist yet create it
|
// If webhook does not exist yet create it
|
||||||
await workflow.runWebhookMethod('create', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
|
await workflow.runWebhookMethod('create', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ export class ActiveWebhooks {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If there was a problem unregister the webhook again
|
// If there was a problem unregister the webhook again
|
||||||
delete this.webhookUrls[webhookKey];
|
delete this.webhookUrls[webhookKey];
|
||||||
delete this.workflowWebhooks[webhookData.workflowId];
|
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +158,7 @@ export class ActiveWebhooks {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all the webhooks of the given workflow
|
* Removes all the webhooks of the given workflows
|
||||||
*/
|
*/
|
||||||
async removeAll(workflows: Workflow[]): Promise<void> {
|
async removeAll(workflows: Workflow[]): Promise<void> {
|
||||||
const removePromises = [];
|
const removePromises = [];
|
||||||
|
|
|
@ -68,12 +68,6 @@ export class TrelloTrigger implements INodeType {
|
||||||
webhookMethods = {
|
webhookMethods = {
|
||||||
default: {
|
default: {
|
||||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
if (this.getWebhookName() === 'setup') {
|
|
||||||
// Is setup-webhook which only gets used once when
|
|
||||||
// the webhook gets created so nothing to do.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const credentials = this.getCredentials('trelloApi');
|
const credentials = this.getCredentials('trelloApi');
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
|
@ -101,12 +95,6 @@ export class TrelloTrigger implements INodeType {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
async create(this: IHookFunctions): Promise<boolean> {
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
if (this.getWebhookName() === 'setup') {
|
|
||||||
// Is setup-webhook which only gets used once when
|
|
||||||
// the webhook gets created so nothing to do.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
|
|
||||||
const credentials = this.getCredentials('trelloApi');
|
const credentials = this.getCredentials('trelloApi');
|
||||||
|
@ -137,12 +125,6 @@ export class TrelloTrigger implements INodeType {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
async delete(this: IHookFunctions): Promise<boolean> {
|
async delete(this: IHookFunctions): Promise<boolean> {
|
||||||
if (this.getWebhookName() === 'setup') {
|
|
||||||
// Is setup-webhook which only gets used once when
|
|
||||||
// the webhook gets created so nothing to do.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
|
||||||
if (webhookData.webhookId !== undefined) {
|
if (webhookData.webhookId !== undefined) {
|
||||||
|
|
Loading…
Reference in a new issue