error (error, transition) public
When attempting to transition into a route, any of the hooks may return a promise that rejects, at which point an error
action will be fired on the partially-entered routes, allowing for per-route error handling logic, or shared error handling logic defined on a parent route.
Here is an example of an error handler that will be invoked for rejected promises from the various hooks on the route, as well as any unhandled errors from child routes:
App.AdminRoute = Ember.Route.extend({ beforeModel: function() { return Ember.RSVP.reject('bad things!'); }, actions: { error: function(error, transition) { // Assuming we got here due to the error in `beforeModel`, // we can expect that error === "bad things!", // but a promise model rejecting would also // call this hook, as would any errors encountered // in `afterModel`. // The `error` hook is also provided the failed // `transition`, which can be stored and later // `.retry()`d if desired. this.transitionTo('login'); } } });
error
actions that bubble up all the way to ApplicationRoute
will fire a default error handler that logs the error. You can specify your own global default error handler by overriding the error
handler on ApplicationRoute
:
App.ApplicationRoute = Ember.Route.extend({ actions: { error: function(error, transition) { this.controllerFor('banner').displayError(error.message); } } });
Parameters:
-
error
Error
-
transition
Transition
Please login to continue.