1

According to Ember Guides, validation errors will be available on the errors property of the model. But I can't get this to work. Say I have "name" and "displayName" property for a person model. What would the payload be if say I have one error which is "name is empty"?

{"errors":[{"title":"name is empty"}, {"title":"other error"}]}

This format is required by jsonapi so I don't know HOW I can end up with what Ember Guides shows below.

If the backend server returns validation errors after trying to save, they will be available on the errors property of your model. Here's how you might display the errors from saving a blog post in your template:

{{#each post.errors.title as |error|}}
  <div class="error">{{error.message}}</div>
{{/each}}
{{#each post.errors.body as |error|}}
  <div class="error">{{error.message}}</div>
{{/each}}
Hao
  • 6,291
  • 9
  • 39
  • 88
  • If I remember it correctly there should also be status code inside error object in string form. ```{"status": "400", "title":"name is empty"}```. Also that iteration looks wrong. How could it iterate over title if title is string? Maybe something like this ```{{#each post.errors as |error|}} {{error.title}}{{/...}}``` – Keo Jan 25 '16 at 19:19
  • I can't get the errros into model. That template is copied from the guides. So maybe they mean any sort of json so It didn't comply to the jsonapi standard. But the jsonapi reply must. So I wonder what is required for such magic to happen. – Hao Jan 26 '16 at 01:49
  • I am not sure if I should close this question because I saw the same question at http://stackoverflow.com/questions/31918565/handling-errors-with-the-now-default-ember-data-json-api-adapter/32059528#32059528 and I got the answer. – Hao Jan 26 '16 at 15:01

0 Answers0