emberjs/data — pull request #1291 by marcoow (2013-09-13 11:31:05+00:00)
Title: added errorProcessor option to RESTAdapter

This adds an `errorProcessor` option to the `RESTAdapter` that allows for easy handling of server-sent validation errors. Instead of having to override the full `RESTAdapter.ajax` method one could not simply specify the `errorProcessor` function like e.g. `headers`:

```js
DS.RESTAdapter.reopen({
errorProcessor: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 422) {
return JSON.parse(jqXHR.responseText).errors;
}
}
});
```

When that handler returns sth., the adapter wraps that in a `DS.InvalidError` so that the errors get assigned to the model's `errors` property.

Unfortunately I don't see a good way to test this as the `ajax` method is stubbed out in the `RESTAdapter` tests and I didn't want to add a dependency to stub on a lower level. Would be glad to add tests of course given some advice on how to do it.