Reputation: 4926
I have a route /products
. In App.ProductsRoute
, I am using a setupController
hook to assign list of products fetched from server to local App.Product objects.
I am setting the model in setupController hook as :
self_controller.set('model', self_controller.store.find('product'));
This works well when HTTP status is 200. But when server returns some HTTP error (like 500-Internal Server Error, 401-Unauthorized Errors, etc) I am getting error as JSON.parse. I am not sure how to handle errors for this.store.find()
calls.
Note: It returns Ember's promiseArray which I need to check once resolved (before actually assigning it to model). Any help on this topic would be much appreciated. Thanks.
Upvotes: 1
Views: 900
Reputation: 51697
What about using the promise's catch
callback to handle the errors? Untested, but something like this should work:
self_controller.store.find('product').then(function(products) {
self_controller.set('model', products);
}).catch(function(reason) {
// Do something to handle the error response...
});
Upvotes: 2