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

你。 提交于 2019-12-12 14:44:41

问题


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 ?


回答1:


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
  });


来源:https://stackoverflow.com/questions/36233353/ember-js-how-to-handle-error-with-ds-store-findrecord-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!