mardi 4 août 2015

Server side error processing in Ember 1.13.3

What is the right way to work with server side errors in Ember 1.13.3?

I'm using RESTAdapter and I tried it with/without this code:

handleResponse: function(status, headers, payload) {
if (payload.errors) {
  return new DS.InvalidError(payload.errors);
}
return this._super(...arguments);

}

My server returns 422 with such JSON:

            {
                errors: [
                    {
                        source: {pointer: 'data'},
                        detail: 'Not saved'
                    }
                ]
            }

In my route I'm saving the model in such way:

job.save().then(function() {
    console.log('OK');
  }).catch(function(err) {
    console.log('Error: ', err, ' Model ', job.get('isError'));
  });

In case of error the flow comes to catch block and 'err' is InvalidError object as expected but job.get('isError') returns false.

And right now I don't know how to get errors in component UI since model property isError is always false.

Thanks




Aucun commentaire:

Enregistrer un commentaire