samedi 2 janvier 2016

How to handle a 400 error with Ember Data (2.4.0-canary)

I can't figure out if my problem has to do with my query or my response or something else.

In my route I'm using a queryRecord:

model(params) {
  return this.store.queryRecord('invitation', { 
    'invitation_token' : params.invitationToken 
  });
},

I'm properly receiving on the server side but I'm testing the case where the invitation token no longer exists. Therefore, the server is returning a 400 with a json payload which has an explanation of the error.

{"error":"Error finding invitation"}

But back on the ember side I'm just getting two errors (really it is just one).

Error while processing route: accept-invitation Ember Data Request GET /api/users/invitation returned a 400
Error: Ember Data Request GET /api/users/invitation returned a 400

It used to be (under Ember 2.2.1):

Error while processing route: accept-invitation Adapter operation failed Error: Adapter operation failed
Error: Adapter operation failed

What am I supposed to be returning from the server in the case that the token wasn't found? These messages makes it looks like something unexpected happen within Ember.

I'd assume that a 400 would tell Ember that there was an error, and it would go to the error state for the route. But instead it goes to the error state at the application level and spits out these error messages in the log.

I'm expecting the server to return a 400, so I'm not sure why Ember is complaining. What should I be returning and how should I properly handle this?




Aucun commentaire:

Enregistrer un commentaire