Guides / n8n
One error workflow for all of n8n, with alerts that actually reach you
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.
What you need
- n8n, cloud or self-hosted.
- An incoming webhook URL from your chat tool: Slack, Google Chat, Discord or ntfy. Each one gives you a URL that accepts a POST and turns it into a message.
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:
| Tool | Body |
|---|---|
| Slack | Send Body on, Body Content Type JSON, Specify Body Using Fields Below. One field: name text, value {{ $json.text }} |
| Google Chat | Same as Slack: one JSON field, text |
| Discord | Same, but name the field content |
| ntfy | Body 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:
- Create a workflow called Error handler test: a Schedule Trigger every minute, then a Stop and Error node with the message Test failure.
- Set its error workflow to Error handler and publish it.
- Wait for the alert and click the link. It should open the failed execution.
- 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
- Hand-typed JSON bodies break. A raw JSON body with an expression inside fails as soon as the error text contains a line break or a quote. Using Fields Below escapes the text for you.
- Posting as yourself means nobody pings you. Chat tools don't notify you about your own messages, so a native chat node signed in with your account delivers alerts you never hear about. A webhook posts as an app and notifies everyone in the channel, you included.
- Trigger failures have no link. Expect the "no execution link" line now and then. It means the workflow never started, which is worth knowing too.
- Unpublished means unprotected. If the handler isn't published, every failure stays silent and nothing tells you so.
Why it's built this way
- One handler, every workflow. Change the message or the tool once and every alert follows.
- A plain HTTP Request over a native node. The same three nodes work with any tool that takes a webhook, and switching tools is one line plus one body field.
- Every message needs a decision. Only failures post. Quiet days stay quiet, so people keep reading the channel.