gpt4 book ai didi

ember.js - Ember 数据 + JSONAPI - 错误 : The adapter rejected the commit because it was invalid

转载 作者:行者123 更新时间:2023-12-02 05:15:12 31 4
gpt4 key购买 nike

我试图通过 POST 提交无效数据使用 Ember Data 2.10 请求基于 JSONAPI 的 API。

API 正确响应 422响应中的代码和此有效负载(请注意,这些是 error objects ,而不是“正常”的 JSONAPI 有效负载响应):

{
"errors": [{
"title": "Title can't be blank",
"id": "title",
"code": "100",
"source": {
"pointer": "/data/attributes/title"
},
"status": "422"
}, {
"title": "Layout can't be blank",
"id": "layout",
"code": "100",
"source": {
"pointer": "/data/relationships/layout"
},
"status": "422"
}, {
"title": "Page type can't be blank",
"id": "page-type",
"code": "100",
"source": {
"pointer": "/data/attributes/page-type"
},
"status": "422"
}]
}

错误似乎基本上可以正常加载到模型中,但我在控制台中收到此错误:
ember.debug.js:19160 Error: The adapter rejected the commit because it was invalid
at ErrorClass.EmberError (ember.debug.js:19083)
at ErrorClass.AdapterError (errors.js:23)
at ErrorClass (errors.js:49)
at Class.handleResponse (rest.js:821)
at Class.handleResponse (data-adapter-mixin.js:100)
at Class.superWrapper [as handleResponse] (ember.debug.js:24805)
at ajaxError (rest.js:1342)
at Class.hash.error (rest.js:916)
at fire (jquery.js:3305)
at Object.fireWith [as rejectWith] (jquery.js:3435)

是什么导致了这个错误?服务器返回的 JSON 负载是否有问题?最近改变的一件事是引入了指向 /data/relationships/layout 的指针。 ; Ember Data 是否因此而窒息?

我可能还注意到,通过 PATCH 提交了类似的不良数据。 request 不会在控制台中触发此错误。

主要问题是这导致验收测试失败,我似乎无法找到解决方法。能够在应用程序中测试这种行为会很好,但我现在只需要将它注释掉。

在更新到 2.10 之前,我也在 E​​mber Data 2.7 上尝试过这个,看看是否能解决它。两个版本都出现相同的错误。

最佳答案

由于您的应用程序使用默认适配器,请确保 JSON:API遵循约定来构建响应

here 上提供了一些指南

关于ember.js - Ember 数据 + JSONAPI - 错误 : The adapter rejected the commit because it was invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40892225/

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