mercredi 16 septembre 2015

Pass a Component to intermediateTransitionTo for Errors

Can a component be specified when calling intermediateTransitionTo on a template?

Specifically, I'd like to have components to cover the common error cases (404, 401, 403) and then default to a fallback component for other errors.

// app/routes/application.js
import Ember from 'ember';

export default Ember.Route.extend({
    intl: Ember.inject.service(),
    beforeModel() {
        this.get('intl').setLocale('en-us');
    },

    model() {
       return this.store.findAll('someModel');
    },

    actions: {
        error: function(error, transition) {
            if (error.status === 404) {
                this.intermediateTransitionTo('error', {
                    into: 'application'
                    // Possible to specify a component here?
                });
            } else if (error.status === 401) {
                this.intermediateTransitionTo('error', {
                    into: 'application'
                    // Possible to specify a component here?
                });
            } else {
                this.intermediateTransitionTo('error', {
                    into: 'application'
                });
            }

            return false;
        }
    }

});

I'm open to other ways of doing this: passing the status code to the template and then writing a helper (?) to assert it may also be an option. My primary goal is to consolidate error handling into the application route so that I can bubble up from other routes and render 'standard' error text to a user.




Aucun commentaire:

Enregistrer un commentaire