Guides / n8n

One error workflow for all of n8n, with alerts that actually reach you

Beginner, 7 min read,

A failed n8n execution is silent by default. You find out when someone asks why the report never arrived. Fix that once: one error workflow, wired to every other workflow, posting the workflow name, the failing node, the error and a link straight to the execution, to whatever chat your team already reads.

Any workflowfails in production
Error TriggerCatch the failure
CodeBuild message
HTTP RequestPost alert

What you need

The webhook URL is a password: anyone with it can post to your channel. Keep it out of screenshots and shared workflow exports.

1. Build the error workflow

Create a new workflow called Error handler with three nodes.

Error Trigger

Add it with default settings. It fires whenever a workflow that points to this handler fails in production.

Code node: Build message

Set Mode to Run Once for Each Item, paste the code, and set TOOL on the first line:

const TOOL = 'slack'; // 'slack', 'google-chat', 'discord' or 'ntfy'

// Each tool writes bold text and links its own way.
const md = TOOL === 'discord';
const plain = TOOL === 'ntfy';
const bold = s => plain ? s : md ? `**${s}**` : `*${s}*`;
const link = (url, label) => plain ? url : md ? `[${label}](${url})` : `<${url}|${label}>`;

// Handles both failure shapes: a node failed mid-run, or the trigger failed.
const { execution = {}, trigger = {}, workflow = {} } = $json;
const error = execution.error ?? trigger.error ?? {};
const name = workflow.name || 'Unnamed workflow';
const node = execution.lastNodeExecuted ?? error.node?.name ?? 'Trigger';
const message = String(error.message ?? 'No error message').slice(0, 500);

const lines = [
  `${bold(name)} failed`,
  `Node: ${node}`,
  `Error: ${message}`,
  execution.url
    ? link(execution.url, 'Open the execution')
    : 'No execution link: the trigger failed before the run started.',
];

return { json: { title: `${name} failed`, text: lines.join('\n'), url: execution.url ?? '' } };

Why a Code node: when a trigger fails (a schedule that can't start, a webhook that can't register), the Error Trigger sends a different shape. There is no execution ID and no link, and the details sit under trigger instead of execution. Expressions written for one shape print undefined for the other. The code covers both and formats the message for your tool.

HTTP Request: Post alert

Set Method to POST and URL to your webhook URL. The body depends on the tool:

ToolBody
SlackSend Body on, Body Content Type JSON, Specify Body Using Fields Below. One field: name text, value {{ $json.text }}
Google ChatSame as Slack: one JSON field, text
DiscordSame, but name the field content
ntfyBody Content Type Raw, content type text/plain, body {{ $json.text }}. Add headers Title = {{ $json.title }} and Click = {{ $json.url }}, so tapping the notification opens the execution

On Microsoft Teams, workflow webhooks expect an Adaptive Card instead of plain text. The pattern stays the same; only this body changes.

In the node's Settings tab, turn on Retry On Fail with 3 tries and 5,000 ms between them. Chat webhooks accept about one message per second, so a burst of failures needs room to retry.

Save, then publish the workflow. An error workflow only runs once it is published.

2. Wire it to every workflow

In each workflow, open Options, then Settings, set Error workflow to Error handler, and save. One handler serves as many workflows as you have.

While you're in Settings, leave Save failed production executions on. The link in the message points to a saved execution; without one, there's nothing to open.

Make this the first setting you touch on every new workflow, before the first node. A workflow without it fails silently.

3. Test it the right way

Running a workflow by hand in the editor never fires the Error Trigger. Only production executions do. So build a failure on purpose:

  1. Create a workflow called Error handler test: a Schedule Trigger every minute, then a Stop and Error node with the message Test failure.
  2. Set its error workflow to Error handler and publish it.
  3. Wait for the alert and click the link. It should open the failed execution.
  4. Unpublish and delete the test workflow.

To tweak the message format without waiting for failures, pin sample data on the Error Trigger and run the handler by hand. The Code and HTTP Request nodes run normally.

The traps

Why it's built this way