App.IndexCrmPersonEditRoute = Ember.Route.extend({
model: function(params) {
var person = this.store.find("person", params.id);
return person;
},
});
which receives the following Router path
...
this.route('edit', { path: ':id'}); // edit person
...
That works nicely for existing people. When the object doesn’t exist, the API returns a 404 with the following content:
{"person": null}
an error "Error while loading route: undefined " happens in JS.
I wish to know if returning 404 + person = null is the correct approach and if it is possible to show a message and redirect the user back to the previous URL (or even not move them if the response is 404).
Each route I expect to have the “Not found” beheaviour, I wrote and Error route, as below (attention to the word “Error” that automatically replaces “Edit”, as EmberJS’ standard:
App.IndexCrmPersonEditRoute = App.NotFoundObjectRoute.extend({
// ...
});
App.IndexCrmPersonErrorRoute = Ember.Route.extend({
// Called for errors like 404 (not found) and 500 (server error)
});
That turned to write also an error view, as below:
You can also handle this globally using ApplicationRoute’s error action
App.ApplicationRoute = Ember.Route.extend({
actions: {
error: function(error, transition){
if (error.status === 0) {
showErrorDialog('Sorry, but we\'re having trouble connecting to the server. This problem is usually the result of a broken Internet connection. You can try refreshing this page.');
} else if (error.status == 403) {
//go to some default route
} else if (error.status == 401) {
//handle 401
} else if (error.status == 404) {
this.transitionTo('fourohfour');
} else {
showErrorDialog(error);
}
}
}
});
Thank you, I imagined that could be possible too. For this specific case I wish to have a customized interface, but certainly the global way will also be useful for the other routes