# Error handling and alerts

> Make n8n workflows recover from small failures by themselves and alert you about the rest, with retries, error outputs and an error workflow.

Source: https://viralistic.nl/help/n8n/error-handling

Every workflow fails sometimes: an API is down, a password changes, someone sends unexpected data. The goal is not zero errors. The goal is that small hiccups fix themselves and real problems reach you quickly, before a customer notices. This article sets that up in three layers.

## Layer 1: Retry on the node

Many errors are temporary, such as a timeout or a rate limit. Let n8n try again.

1. Open the node that calls an outside service.
2. Go to its **Settings** tab.
3. Turn on **Retry On Fail**.
4. Set **Max Tries** (for example 3) and **Wait Between Tries** (for example 5000 ms).

Use this on nodes that read data or call APIs. Be careful with nodes that create things, like sending an email or creating an invoice: a retry after a partial success can create duplicates.

## Layer 2: Decide what happens on an error

In the same **Settings** tab, **On Error** controls what the node does when it still fails:

| Option                        | What happens                                         | Use when                                               |
| ----------------------------- | ---------------------------------------------------- | ------------------------------------------------------ |
| Stop Workflow                 | The run stops and is marked as failed                | The default. The rest makes no sense without this step |
| Continue                      | The workflow continues with the last valid data      | The step is optional                                   |
| Continue (using error output) | The node gets a second, error output you can connect | You want to handle the failure yourself                |

The error output is the most useful. For example, when one row in a batch of 100 fails, route that row to a "needs attention" data table and let the other 99 continue.

## Layer 3: An error workflow for alerts

An error workflow runs automatically whenever a production run of another workflow fails. You build it once and attach it to all your workflows.

### Build the error workflow

1. Create a new workflow called `Error alerts`.
2. Add the **Error Trigger** node as the first step.
3. Add a node that notifies you, such as Slack, Gmail or Telegram.
4. Write a message with expressions from the error data:

```text
Workflow failed: {{ $json.workflow.name }}
Node: {{ $json.execution.lastNodeExecuted }}
Error: {{ $json.execution.error.message }}
Open: {{ $json.execution.url }}
```

You do not need to publish this workflow. The Error Trigger works without publishing.

### Attach it to your workflows

1. Open a workflow you want to monitor.
2. Open the workflow menu (the three dots) and choose **Settings**.
3. Under **Error workflow**, choose `Error alerts`.
4. Save.

Repeat this for every production workflow. Make it part of your checklist before you publish.

> **Note:** The error workflow only fires for automatic, production runs. Clicking Execute workflow in the editor will not trigger it. To test, publish a small workflow that fails on purpose, for example a Schedule Trigger followed by a **Stop and Error** node.

## Fail on purpose with Stop and Error

Not every problem throws an error. An empty search result or a missing email address can be just as bad. Use an IF node to detect the situation, then a **Stop and Error** node with a clear message, such as "No invoice number found". The run is marked as failed and your error workflow sends the alert.

## Find and retry failed runs

1. Open the **Executions** tab of a workflow, or the overview of all executions.
2. Filter on failed runs.
3. Open one to see exactly which node failed and with what data.
4. Fix the cause, then retry the execution. You can retry with the current workflow or with the original version.

> **Tip:** On a failed execution, select **Debug in editor** to load its data into the workflow and fix the problem with the exact same input. This is available on n8n Cloud and on registered or paid self-hosted editions.

## A simple alert policy

- **Critical workflows** (orders, customer email): alert immediately, to a channel someone watches.
- **Background jobs** (reports, syncs): a daily digest is often enough. Log errors to a data table and send one summary each morning.
- **Avoid alert fatigue:** if an alert fires every day and nobody acts, fix the cause or remove the alert.

## Next steps

- [Store data with Data Tables](https://viralistic.nl/help/n8n/data-tables)
- [Update and back up a self-hosted n8n](https://viralistic.nl/help/n8n/self-hosting-maintenance)
- [The AI Agent node explained](https://viralistic.nl/help/n8n/ai-agent-node)
