我从后端收到错误:
{
"errors": {
"extra_comments": [
"This field may not be null."
],
"name": [
"This field may not be null."
],
"due_date": [
"This field may not be null."
],
"price": [
"This field may not be null."
],
"payment_type": [
"This field may not be null."
],
"description": [
"This field may not be null."
]
}
}
我尝试在我的模板中显示它们:
{{#each model.errors.messages as |message|}}
<div class="error">
{{message}}
</div>
{{/each}}
没有显示任何内容。 EmberData有问题吗? Ember模板语法更改的问题? Ember有问题吗?适配器?我的后端?不知道。问题表面太大了。我怎么能:
model.errors
?model.errors
?总的来说,我遇到的是Ember的新版本很难调试。每当我在控制台中显示任何Ember对象时,我只会看到一些Computed
属性,每当我试图查看它们时都不会计算它们。
我的后端是:
我不确定django-rest-framework-json-api
是否能够返回JSON Api符合错误。我打开了issue。
答案 0 :(得分:2)
您从后端收到的错误并非JSON API符合errors。
您必须在自定义序列化程序的extractErrors
方法中转换错误(有关示例,请参阅RESTSerializer文档),或者更改后端以返回符合JSON API的错误。
multiple errors符合JSON API
规范的示例:
{
"errors": [
{
"status": "403",
"source": { "pointer": "/data/attributes/secret-powers" },
"detail": "Editing secret powers is not authorized on Sundays."
},
{
"status": "422",
"source": { "pointer": "/data/attributes/volume" },
"detail": "Volume does not, in fact, go to 11."
},
{
"status": "500",
"source": { "pointer": "/data/attributes/reputation" },
"title": "The backend responded with an error",
"detail": "Reputation service not responding after three requests."
}
]
}
答案 1 :(得分:0)
在代码I found上查看django端需要此设置:
REST_FRAMEWORK = {
...
'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
...
}