gpt4 book ai didi

javascript - Ember 1.13.3 中服务器端错误处理

转载 作者:行者123 更新时间:2023-11-28 00:01:00 25 4
gpt4 key购买 nike

在 Ember 1.13.3 中处理服务器端错误的正确方法是什么?

我正在使用 RESTAdapter,并且我尝试使用/不使用以下代码:

handleResponse: function(status, headers, payload) {
if (payload.errors) {
return new DS.InvalidError(payload.errors);
}
return this._super(...arguments);

}

我的服务器返回 422 并带有这样的 JSON:

            {
errors: [
{
source: {pointer: 'data'},
detail: 'Not saved'
}
]
}

在我的 route ,我以这种方式保存模型:

job.save().then(function() {
console.log('OK');
}).catch(function(err) {
console.log('Error: ', err, ' Model ', job.get('isError'));
});

如果出现错误,流程将进入 catch block ,并且“err”按预期是 InvalidError 对象,但 job.get('isError') 返回 false。

现在我不知道如何在组件 UI 中获取错误,因为模型属性 isError 始终为 false。

谢谢

最佳答案

你没有捕获 isError 的要点

If true the adapter reported that it was unable to save local changes to the backend for any reason other than a server-side validation error.

您应该检查的是 isValid

A record will be in the valid state when the adapter did not report any server-side validation failures.

关于javascript - Ember 1.13.3 中服务器端错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31805412/

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