Error Subroutes
Let’s talk about error subroutes and how to use them.
We'll cover the following
How error subroutes work
Error subroutes are activated when a model hook throws an error, either because the backend returned an error response or because the application code, itself, ran into a problem.
Error subroutes work exactly the same way as loading subroutes:
- An
error
event is fired on the route where the error was produced. - The default behavior is to render an
error
template on the level of the route that triggered the error. - The entire Ember arsenal is at our disposal to implement a custom behavior. It is just a matter of implementing an action handler for the
error
action in the route.
It only takes a template to show an error message when loading a particular band does not work as it should. Let’s create another template:
ember g template bands/band/error
We can display a similar panel, as we did for the loading template, with colors that indicate something slightly bad has happened:
Get hands-on with 1200+ tech skills courses.