Handling promise rejections in actions hash

What’s the typical way to handle promise rejections (most pertinently, 401 or 503 server errors with ember-data) in a route’s or controller’s actions hash?

I’m basically looking for a way to globally handle promise rejections outside of a transition, without adding the same error-handling boilerplate to all my promises.

Boiling it down further, I want to transition to the error route whenever a 503 error is encountered (regardless of whether it occurred inside or outside a model or beforeModel hook).

Anyone found a good way to do this?

I’m not sure how it glues with Ember Data, but there is already a built-in handler for rejected transitions: Loading / Error Substates - Routing - Ember Guides

Resurrecting this thread.

@Oddskar - the link you provided demonstrates behaviour for errors that occur during a transition. I’m looking to emulate the same behaviour for actions that are triggered outside of a transition (say, a save action that is triggered in response to a user’s click).

I’d love it if the error action could somehow be triggered when any error occurs within the application (right now, only Ember.onerror is fired, which is outside of the context of my App).

1 Like