gpt4 book ai didi

Ember.js - 如何使用 DS.store.findRecord() 方法处理错误

转载 作者:行者123 更新时间:2023-12-01 13:45:55 24 4
gpt4 key购买 nike

我正在使用以下简单代码来检索用户来自服务器。

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

我正在使用它来检索用户。如果在 0 id 上找不到用户,

服务器根据 json api 返回 404 和错误。

但是我怎么知道客户端的错误呢?

最佳答案

取自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.

由于返回值是一个 promise ,您可以将其用作任何其他 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
});

关于Ember.js - 如何使用 DS.store.findRecord() 方法处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36233353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com