Error handling

Since any API endpoint can return an error during an execution of a scenario, Make brought a way, how to handle such errors. Therefore, all apps in Make, custom included, should have error handling implemented. This way, the modules are more transparent as users of them exactly know, what caused the error. Also, error handling in a scenario can be used.

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:

In DevTool, you should see this output:

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:

{
	"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"]
	}
}

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.

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

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.

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!

Last updated