0

I am struggling to handle an errors response using Ember Data and the ActiveModelAdapter. I have Googled around and the consensus is that the json format needs to be {errors: {field_name: ["My error message", "another error"]}} but although I am returning this in a HTTP 500 response my model's "errors" property remains an empty Ember object.

Also, from what I have read Ember Data is compatible with the JSON API standard (created by Ember's Yehuda Katz) so I'd like to return errors in the following format if possible:

http://jsonapi.org/format/#errors

This would allow me to return a "title", "code" etc. However, all of the examples that I can find of Ember Data handling errors do not demonstrate this format being used and they seem to limit the error format to a field name key and one or more message strings. Am I mistaken in thinking that the ActiveModelAdapter can handle this type of response?

If anyone could help me with this I'd be grateful.

Thanks.

danr1979
  • 461
  • 1
  • 3
  • 10
  • I'm also using the errors as in http://emberjs.com/api/data/classes/DS.Errors.html. Beware that the fields in the errors aggregate must be underscored (last_name vs. lastName)... because of the ActiveModelSerializer. – enspandi May 16 '15 at 15:57
  • I'd also suggest returning 400 Bad Request instead of 500 if the given input may be the cause of failure... – enspandi May 16 '15 at 16:00
  • Thanks for your response. As you can see in my example code I am using an underscored field & I have tried different error codes (404 for a not found resource, 400 for a bad request etc) but to no avail. However, I checked out your link to the DS.Errors class & found that, contrary to many of the examples out there, it seems as if an "errors" key name is not required in the returned json. Maybe that is my problem so I'll try again when I get a chance. Thanks! – danr1979 May 16 '15 at 19:50

0 Answers0