Reputation: 1514
I'm getting this error, where I am trying to retrieve a user that DO NOT exist on purpose ofcouse:
Error while processing route: user Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined
Instead of this console error, can I give the user an error message saying, 'the user does not exist' or something like that through the route or a controller to the view?
Heres my route
App.Router.map(function () {
this.resource('user', { path: '/user/:user_id' });
});
And here i retrieve the user
App.UserRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('user', params.user_id);
},
});
Hope you understand and can help me proceed. Thanks in regards!
Upvotes: 1
Views: 1071
Reputation: 37369
So I'm not sure why missing fixtures data is giving you that particular error, but you can catch errors in routes using the error
event. You can read about it here. You'll have to do something like this:
App.UserRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('user', params.user_id);
},
actions: {
error: function(error, transition) {
// Display some sort of message
alert("Sorry, we couldn't find that user.");
// Redirect to a different part of the application
this.transitionTo('index');
}
}
});
Upvotes: 1