ember数据 JSONAPI-错误:适配器拒绝了该提交,因为它无效



我试图通过POST请求将无效数据提交给带有Ember Data 2.10的基于JSONAPI的API。

API使用422代码正确响应,并且此有效载荷在响应中(请注意,这些是错误对象,而不是"正常" 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数据是否窒息了?

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

主要问题是这导致接受测试失败,我似乎找不到解决方法。能够在应用程序中测试此行为会很高兴,但是我只需要将其排除在外。

在更新为2.10之前,我还尝试了Ember Data 2.7,以查看是否可以解决它。两个版本都会遇到相同的错误。

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

在此处提供了少数指南

相关内容

最新更新