From 075aca94970c2d86cad659e4449c62f4cb99b837 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 19 Feb 2020 11:29:03 -0600 Subject: [PATCH] :zap: Add execution url on Error-Workflow trigger --- docs/workflow.md | 2 ++ packages/cli/src/WorkflowExecuteAdditionalData.ts | 7 +++++++ packages/nodes-base/nodes/ErrorTrigger.node.ts | 12 +++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/workflow.md b/docs/workflow.md index 314715d8c5..7df5c671f3 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -37,6 +37,7 @@ The "Error Trigger" node will trigger in case the execution fails and receives i { "execution": { "id": "231", + "url": "https://n8n.example.com/execution/231", "retryOf": "34", "error": { "message": "Example Error Message", @@ -56,6 +57,7 @@ The "Error Trigger" node will trigger in case the execution fails and receives i All information is always present except: - **execution.id**: Only present when the execution gets saved in the Database +- **execution.url**: Only present when the execution gets saved in the Database - **execution.retryOf**: Only present when the execution is a retry of a previously failed one diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 9d0fe2a038..9665080ebd 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -51,10 +51,17 @@ import * as config from '../config'; */ function executeErrorWorkflow(workflowData: IWorkflowBase, fullRunData: IRun, mode: WorkflowExecuteMode, executionId?: string, retryOf?: string): void { // Check if there was an error and if so if an errorWorkflow is set + + let pastExecutionUrl: string | undefined = undefined; + if (executionId !== undefined) { + pastExecutionUrl = `${WebhookHelpers.getWebhookBaseUrl()}execution/${executionId}`; + } + if (fullRunData.data.resultData.error !== undefined && workflowData.settings !== undefined && workflowData.settings.errorWorkflow) { const workflowErrorData = { execution: { id: executionId, + url: pastExecutionUrl, error: fullRunData.data.resultData.error, lastNodeExecuted: fullRunData.data.resultData.lastNodeExecuted!, mode, diff --git a/packages/nodes-base/nodes/ErrorTrigger.node.ts b/packages/nodes-base/nodes/ErrorTrigger.node.ts index 293c64b480..4899c20e84 100644 --- a/packages/nodes-base/nodes/ErrorTrigger.node.ts +++ b/packages/nodes-base/nodes/ErrorTrigger.node.ts @@ -33,9 +33,19 @@ export class ErrorTrigger implements INodeType { if (mode === 'manual' && items.length === 1 && Object.keys(items[0].json).length === 0 && items[0].binary === undefined) { // If we are in manual mode and no input data got provided we return // example data to allow to develope and test errorWorkflows easily + + const restApiUrl = this.getRestApiUrl(); + + const urlParts = restApiUrl.split('/'); + urlParts.pop(); + urlParts.push('execution'); + + const id = 231; + items[0].json = { execution: { - id: '231', + id, + url: `${urlParts.join('/')}/${id}`, retryOf: '34', error: { message: 'Example Error Message',