# Error handling

The best way to deal with errors is to use an error handler. An error handler connects to a module with the error handling route. When the module outputs an error, the error handling route activates and runs the error handler.

When all errors are handled, Make keeps scheduling scenario runs instead of disabling the scenario.

{% hint style="info" %}
Read more about error handling in Make:

* [Introduction to errors and warnings](https://help.make.com/introduction-to-errors-and-warnings)
* [Overview of error handling](broken://spaces/zrfspnCn5cw8JBuZupIN)
* [Quick error handling reference guide](https://help.make.com/quick-error-handling-reference)
  {% endhint %}

## Setting up an error handling for our demo API

> *When you were trying your new search module, you were probably experiencing error 401, but you didn't know why was that, if you didn't check Integromat DevTool. Since Make offers advanced error handling, you should set your app the way, so you could understand what is wrong with your module/scenario right away and use error handlers.*

Enter your search module into your scenario and create a new connection with a random API key, if you haven't done so before. You should see the error:

<div align="left"><img src="/files/tSiJXoVuA0LQQGB8lHxP" alt="Error 401 Before Implementing Error Handling" width="518"></div>

In DevTool, you should see this output:

<div align="left"><img src="/files/M6YNDuYwRzBhSWs6zyWr" alt="Error in the DevTool"></div>

We need to make sure the error from the body of the response is returned in the module's output as well.

As you learned before, error handling should take part in base, since it is an element, which is shared among all modules and remote procedures. Therefore, open base and replace the current code with the code below:

```javascript
{
	"baseUrl": "http://demo-api.integrokit.com/api/v1",
	"headers": {
		"api-token": "{{connection.apiKey}}"
		},
	"response": {
		 "error": {
            	     "message": "[{{statusCode}}] {{body.error}}"
        }},
	"log": {
		"sanitize": ["request.headers.api-token"]
	}
}
```

{% hint style="info" %}
Notice, that a new element `response` with `error` handling was added.

Basically, we mapped the `error` parameter from the response body. So now, when an error is returned from the API, the error message contains the `statusCode` together with `error` wording.
{% endhint %}

Now, go to your scenario again, and execute the search module. You should now see the detailed wording of the error:

<div align="left"><img src="/files/VjpO83RMdQJH6nIvzUcg" alt="Error 401 with Detailed Wording after Implementing Error Handling" width="529"></div>

{% hint style="info" %}
Notice, that the wording of the error is now available. Thanks to this, you know where is an error and how to solve/handle it.
{% endhint %}

> *Voila! You just learned all the basics of custom app development in Make!*
>
> *If you want to continue in development of your custom apps, you can explore our docs and learn more!*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.make.com/custom-apps-documentation/create-your-first-app/error-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
