【问题标题】:Ember errors not populated in model with RESTAdapter in Ember 2.4.5 and Ember DATA 2.4.0在 Ember 2.4.5 和 Ember DATA 2.4.0 中使用 RESTAdapter 的模型中未填充 Ember 错误
【发布时间】:2016-04-20 10:22:17
【问题描述】:

我正在尝试处理 Ember 应用程序中的服务器错误。

我在 ember 应用中运行以下代码:

customization.save().catch(function (error) {
      console.log(error);
      console.log(customization.get('errors'));
      console.log(customization.get('errors.length'));
    });

我的服务器正在使用有效负载中的以下 json 回答 422 状态:

{  
   "errors":[  
      {  
         "code":"app.customization.validationError.duplicateCustomizationName",
         "detail":"a customization with same name already exists",
         "source":{  
            "pointer":"customization/name"
         }
      }
   ]
}

错误是InvalidError,但customization.get('errors.length') 始终为0。

我在 Ember 2.4.5 和 Ember DATA 2.4.0 中使用 DS.RESTAdapter 和 DS.RESTSerializer。

我错过了什么?

谢谢

【问题讨论】:

    标签: ember.js ember-data ember-cli


    【解决方案1】:

    好吧,我终于想通了。即使您没有使用 DS.JSONAPIAdapter,source.pointer 中的路径也必须采用 JSONAPI 样式。

    发送这个:

    ...
    "pointer":"data/attributes/name"
    ...
    

    解决了这个问题。

    我以为指针中的路径指的是模型对应的实际JSON中字段的路径,但这显然是错误的。

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多