I have the following in my user route (Ember 1.9) so that I can preemptively avoid having ember data make a call to my server when a non-int parameter is in the url:
MyApp.UserRoute = Ember.Route.extend({
model: function (params, transition) {
var identifier = params.identifier;
if (isNaN(parseInt(identifier))) {
this.intermediateTransitionTo("error", new Error("oops"));
return true;
}
else {
return this.store.find('user', identifier);
}
}
});
I'm returning true because that's apparently what will make error events bubble up. This works well enough but it gets odd since the transition isn't completely interrupted or aborted, so then it continues on to my UserIndexRoute:
MyApp.UserIndexRoute = Ember.Route.extend({
redirect: function(model){
model.get('someprop'); //blows up because get is undefined on true
}
});
Is there a "standard" return value that will act just like a failed promise? I've also seen examples in error handling tutorials where to make a promise reject, a new Ember.RSVP.Promise is returned with a reject("error") inside, but I don't know if that's suitable for production.
Aucun commentaire:
Enregistrer un commentaire