Search code examples
ember.jsember-datajson-api

Ember JSONAPIAdapter server reject response format?


I am using JSONAPIAdapter in Ember Data, in case server wants to reject the request, server returns HTTP status code 400 Bad Request with json payload like this:

{"errors":[{"code":"698","title":"Invalid request"}]}

According to the jsonapi.org, I think this is the correct format( a array of error objects keyed by "errors" )

But when I run Ember, I always get a Adapter error. Is my format incorrect?

enter image description here


Solution

  • Getting AdapterError is correct behavior in this case. You can see that your payload from the server is correctly parsed by Ember and errors property of Error object you've logged is populated.

    So, your adapter tries for example to get some records, but instead it gets 400 error and it's expected that you will get AdapterError.

    If you don't want to get AdapterError you have to change the way your server behaves and instead of rejecting request provide model data.

    You can also catch AdapterError if this is expected for you and handle that manually.