DS.InvalidError Class packages/ember-data/lib/system/adapter.js:17

A DS.InvalidError is used by an adapter to signal the external API was unable to process a request because the content was not semantically correct or meaningful per the API. Usually this means a record failed some form of server side validation. When a promise from an adapter is rejected with a DS.InvalidError the record will transition to the invalid state and the errors will be set to the errors property on the record.

Example

1
2
3
4
5
6
7
8
9
10
11
12
App.ApplicationAdapter = DS.RESTAdapter.extend({
  ajaxError: function(jqXHR) {
    var error = this._super(jqXHR);

    if (jqXHR && jqXHR.status === 422) {
      var jsonErrors = Ember.$.parseJSON(jqXHR.responseText)["errors"];
      return new DS.InvalidError(jsonErrors);
    } else {
      return error;
    }
  }
});

The DS.InvalidError must be constructed with a single object whose keys are the invalid model properties, and whose values are the corresponding error messages. For example:

1
2
3
4
return new DS.InvalidError({
  length: 'Must be less than 15',
  name: 'Must not be blank
});