Gustavo Siqueira
Gustavo Siqueira

Reputation: 862

default error template on Ember not loading

I'm not sure if I'm doing something wrong, but at my ApplicationRoute I have something like that:

actions: {
    error: function(error, transition) {
        var self = this;
        metadata = {
            'timeout': {
                action: function(error, transition) {
                   BootstrapDialog.alert({message: 'Request Timeout!'});
                }
            },
            'forbidden': {
                action: function(error, transition) {
                    self.transitionTo('companies');
                }
            },
            'unauthorized': {
                action: function(error, transition) {
                    window.location.replace(error.responseJSON.redirect_url);
                }
            },
            'bad gateway': {
                action: function(error, transition) {
                    throw new Error("Error");
                }
            }
        };

        if(error.statusText.toLowerCase() in metadata) {
            metadata[error.statusText.toLowerCase()].action(error, transition);
        }
    }
}

and I have a error.hbs templete, which I expect to be fired on 'bad gateway' error, but the template doesn't load, there is any specific way for me to load the default error template?

Thanks.

Upvotes: 3

Views: 2908

Answers (3)

atomkirk
atomkirk

Reputation: 3801

Just return true so the error keeps bubbling up:

actions: {
  error(transition, originRoute) {
    return true;
  }
}

How to both have an action error and render template in EmberJS

Upvotes: 2

Nelu
Nelu

Reputation: 18770

Adding to @ppcano's answer:

If you need to display the error message on the error template, pass in the error object into the error action, as shown here.

actions: {
  error: function(error) {
    // e.g. you can have a controller for the error route and set error.message and error.status here
    this.render('error', {
      into: 'application'
    });
  }
}

Upvotes: 1

ppcano
ppcano

Reputation: 2861

If you define the application error handler, you must render the error template.

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    error: function() {

      this.render('error', {
        into: 'application'
      });
    }
  }

});

An example is available here.

You could remove the error handler and check how the error template is rendered by ember.

Upvotes: 2

Related Questions