Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember.js 处理 rails 过来的 Validation errors 问题? #9

Closed
wppurking opened this issue Sep 16, 2015 · 0 comments
Closed

ember.js 处理 rails 过来的 Validation errors 问题? #9

wppurking opened this issue Sep 16, 2015 · 0 comments

Comments

@wppurking
Copy link
Owner

ember.js 中使用 DS.Errors 来封装的 model 中的各项错误, 不愧是来自 jQuery, Rails 社区的 Yehuda Katz 将好东西直接拿过了, 与 Rails 中的 Errors 处理基本上一个模子. 借用了 JavaScript 原生的 Error class 然后封装成 DS.Errors, 当 DS.Model 进行 save/update 等方法执行错误后需要满足两个条件则会自动解析内容并且填充到 DS.Model.errors 中, 其就是 DS.Errors 实例.

  1. 要求服务器端返回 422 错误
  2. 返回的结果是 {attribute: [...message]}.
    错误填充到 DS.Model.errors 然后在页面上可以 DS.Model.errors.username 获取展示错误以及通过 DS.Model.errors.messages 展示全部错误信息.

在 ember-data 中, 已经根据 JSONAPI 规范进行了处理, 详情见: #3194

  • 服务器响应 4xx , 5xx 错误
  • 使用专门的 error Object 来封装错误
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant