3

I am using following simple code to retrieve user from server.

var someUser = this.store.findRecord('user', 0);

I am using this for retrieving the user. if user is not found on 0 id,

server returns 404. and error as per json api.

but how do i know about error on client side about it ?

Addison
  • 7,322
  • 2
  • 39
  • 55
iamgopal
  • 8,806
  • 6
  • 38
  • 52
  • 1
    You can find answer in [docs](https://guides.emberjs.com/v2.4.0/routing/loading-and-error-substates/#toc_code-error-code-substates). Also you are welcome to read [my post](http://blog.gennady.pp.ua/how-to-handle-backend-errors-in-ember-js-properly/) about error handling – Gennady Dogaev Mar 27 '16 at 12:31

1 Answers1

4

Taken from Ember guides:

Use store.findRecord() to retrieve a record by its type and ID. This will return a promise that fulfills with the requested record.

Since the return value is a promise, you can use it as any other promise:

this.store.findRecord('user', 0)
  .then(function(user){
    // user has been found
    someUser = user;
  }).catch(function(error){
    // user not found or any other error
  });
Pavol
  • 1,200
  • 8
  • 20