Reputation: 1031
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
Upvotes: 1
Views: 80
Reputation: 9330
You are missing the point of isError
If true the adapter reported that it was unable to save local changes to the backend for any reason other than a server-side validation error.
What you should be checking is isValid
A record will be in the valid state when the adapter did not report any server-side validation failures.
Upvotes: 1