gpt4 book ai didi

javascript - Ember JS 错误处理 : Accessing errors in model not possible due to adapter error

转载 作者:行者123 更新时间:2023-12-03 08:50:36 26 4
gpt4 key购买 nike

Ember 的版本是 2.10.2。

我在这里问了一个关于错误响应和处理的问题:Assertion Failed: `AdapterError` expects json-api formatted errors array

我以为它已经解决了,但事实并非如此。我无法将我的错误绑定(bind)到模型(这是正确的放置方式吗?)。我现在有一个适配器错误说:

message:"The adapter rejected the commit because it was invalid"

错误响应如下所示:
{
"errors": [{
"source": {
"pointer": "\/data\/attributes\/email",
"parameter": null
},
"detail": "user.email.not_blank"
}]
}

更新:我的提交功能
user.save().then(
() => {
console.log('user saved');
}, (adapterError) => {
console.log(adapterError);
}
);

有人可以告诉我如何通过模型获取错误消息吗?

最佳答案

使用 extractErrors ?

"extractErrors is used to extract model errors when a call to DS.Model#save fails with an InvalidError. By default Ember Data expects error information to be located on the errors property of the payload object."



https://www.emberjs.com/api/ember-data/2.16/classes/DS.JSONSerializer/methods/extractErrors?anchor=extractErrors

关于javascript - Ember JS 错误处理 : Accessing errors in model not possible due to adapter error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41903458/

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