1

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.

1 Answer 1

2

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...
});
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, I am able to enter catch() function when there is an error. But the problem is when I call some_product.save() and get an error, it still stores the product in local ember-data array. How can I undo that in catch()..? Thanks.
Maybe rollback?
Yes. I solved it using rollback on particular record. Thanks a lot for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.