Custom error handlers

Besides customizing the error page, you can also customize how all errors are handled and override the default system behavior.

For example, the default ‘Page Not Found’ error would navigate to the /error page but if you would rather show a toaster alert, the following could be added to the App model.

{
	"errorHandlers": [{
        "actions": [{
            "action": "showAlert",
            "function": "action.options.text = action.options.error.message",
            "options": {
                "text": "",
                "title": "Error",
                "type": "error"
            }
        }],
        "codes": ["404"]
    }]
}

As it can be seen above, custom behaviours are added under a reserved global actions key errorHandlers, and that will be an array of objects. Each object having have codes and actions.

KeyValue

codes

array of error codes that the associated actions will run with.

actions

array of actions

The result from the example code above is the alert shown below.

The error data can be found under options for each action of the array, for a given code. The error object has the same shape as previously presented here and can be accessed as follows:

KeyPath

code

actions.options.error.code

description

actions.options.error.description

message

actions.options.error.message

Last updated