Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js - How to handle error with DS.store.findRecord() method

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 ?

like image 342
iamgopal Avatar asked Nov 26 '25 04:11

iamgopal


1 Answers

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
  });
like image 61
Pavol Avatar answered Nov 28 '25 00:11

Pavol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!