# Error handling

Since any API endpoint can return an error during an execution of a scenario, Make provides methods to handle errors and keep scenarios reliable and functional.

All apps in Make should implement error handling to ensure that users understand the cause of any errors. Error handling should always be customized to the type of error and how the API returns the error.

{% hint style="info" %}
Read more about error handling in the Help Center:

* [Introduction to errors and warnings](https://help.make.com/introduction-to-errors-and-warnings)
* [Overview of error handling](https://help.make.com/overview-of-error-handling)
* [Error handlers](https://help.make.com/error-handlers)
  {% endhint %}

{% hint style="warning" %}
When the service returns an HTTP error, it is not possible to evaluate it as a success.
{% endhint %}

## Error handling: 401 error

{% tabs %}
{% tab title="Output from API" %}

<div align="left"><figure><img src="https://1562974717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNS0mCBwODiYtOVXjc6qf%2Fuploads%2Fgit-blob-f39d331cf9eb9be74115c2da97576be1a7c099b4%2FScreen%20Shot%202022-08-21%20at%2017.25.44.png?alt=media" alt="" width="549"><figcaption><p>Error in Make DevTool</p></figcaption></figure></div>
{% endtab %}

{% tab title="Without error handling" %}

<div align="left"><figure><img src="https://1562974717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNS0mCBwODiYtOVXjc6qf%2Fuploads%2Fgit-blob-044c1def56b129fdbd5a61e2f37e6f1882ff204d%2Ferrorhandling_401without.png?alt=media" alt="" width="336"><figcaption><p>Error with no detail message</p></figcaption></figure></div>
{% endtab %}

{% tab title="With error handling" %}

<div align="left"><figure><img src="https://1562974717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNS0mCBwODiYtOVXjc6qf%2Fuploads%2Fgit-blob-0c6732a319e72c93246ba57f80adc7a92e278f44%2Ferrorhandling_401with.png?alt=media" alt="" width="337"><figcaption><p>Error with a detail message</p></figcaption></figure></div>

{% hint style="info" %}
With error handling, details of the error are available and the user will know how to solve the problem.
{% endhint %}
{% endtab %}

{% tab title="Code" %}

```json
{
    // ...
    "response": {
        "error": {
            "message": "[{{statusCode}}] {{body.error}}"
        }
    },
    // ...
}
```

{% endtab %}
{% endtabs %}

## HTTP 4xx and 5xx error handling

When the response returns a 4xx or 5xx HTTP error code, this is automatically considered an error. If the `error` directive is not specified, the user will only see the status code that was returned. You should customize the message shown to the user with the `error` or `error.message` directive.

{% tabs %}
{% tab title="Code example" %}

```json
{
    "response": {
        "error": {
            "type": "RuntimeError",
            "message": "[{{statusCode}}] {{body.error.message}}",
            "400": {
                "type": "DataError",
                "message": "[{{statusCode}}] {{body.error.message}}"
            },
            "500": {
                "type": "ConnectionError",
                "message": "[{{statusCode}}] {{body.error.message}}"
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}

## HTTP 2xx and 3xx error handling

Some APIs signal an error with a 200 status code and a flag in the body. In this situation, use the `valid` directive to tell the user if the response is valid or not.

{% tabs %}
{% tab title="Code example" %}

```json
{
    "response": {
            "valid": {
                "condition": "{{body.status != 'error'}}"
            },
            "error": {
                "200": {
                    "message": "{{ifempty(errors(body.message), body.message)}}"
                },
                "message": "[{{statusCode}}]: {{body.reason}}"
            }
        }
}
```

{% endtab %}
{% endtabs %}

## Custom error handling based on status codes

You can further customize what error message will be shown to the user based on the status code. To do this, add your status code to the `error` directive.

{% tabs %}
{% tab title="Code example" %}

```json
{
    "response": {
        "error": {
            "message": "Generic error message",
            "400": {
                "message": "Your request was invalid"
            },
            "500": {
                "message": "The server was not able to handle your request"
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}

## Available error types

When handling an error, you can specify the type of the error.

<table><thead><tr><th width="244.81488037109375" valign="top">Error type</th><th valign="top">Description</th></tr></thead><tbody><tr><td valign="top"><code>UnknownError</code></td><td valign="top"></td></tr><tr><td valign="top"><code>RuntimeError</code> (default)</td><td valign="top">Primary error type. Execution is interrupted and rolled back.</td></tr><tr><td valign="top"><code>InconsistencyError</code></td><td valign="top"></td></tr><tr><td valign="top"><code>DataError</code></td><td valign="top">Incoming data is invalid. If incomplete executions are enabled, execution is interrupted and the state is stored. The user is able to repair the data and resume execution.</td></tr><tr><td valign="top"><code>RateLimitError</code></td><td valign="top">Service responded with rate-limit related error. Applies delay to the next execution of a scenario.</td></tr><tr><td valign="top"><code>OutOfSpaceError</code></td><td valign="top">The user is out of space.</td></tr><tr><td valign="top"><code>ConnectionError</code></td><td valign="top">Connection-related problem. Applies delay to the next execution of a scenario.</td></tr><tr><td valign="top"><code>InvalidConfigurationError</code></td><td valign="top">Configuration-related problem. Deactivates the scenario and notifies the user.</td></tr><tr><td valign="top"><code>InvalidAccessTokenError</code></td><td valign="top">Access token-related problem. Deactivates the scenario and notifies the user.</td></tr><tr><td valign="top"><code>UnexpectedError</code></td><td valign="top"></td></tr><tr><td valign="top"><code>MaxResultsExceededError</code></td><td valign="top"></td></tr><tr><td valign="top"><code>IncompleteDataError</code></td><td valign="top">Incoming data is incomplete.</td></tr><tr><td valign="top"><code>DuplicateDataError</code></td><td valign="top">Reports error as warning and does not interrupt execution. If incomplete executions are enabled, execution is interrupted and the state is stored. The user is able to repair the data and resume execution.</td></tr></tbody></table>

### Error handling with type

{% tabs %}
{% tab title="Code example" %}

```json
{
    "response": {
        "error": {
            "type": "DataError",
            "message": "[{{statusCode}}] {{body.message}}"
        }
    }
}
```

{% endtab %}
{% endtabs %}
