Skip to content

Commit

Permalink
Merge pull request #3534 from tchak/rename-error-attribute
Browse files Browse the repository at this point in the history
Rename error attribute
  • Loading branch information
bmac committed Jul 17, 2015
2 parents 3fef569 + 687fc9f commit 1bea9b7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/ember-data/lib/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function AbortError() {
AbortError.prototype = Object.create(AdapterError.prototype);

/**
@method errorsHashToArray
@private
*/
export function errorsHashToArray(errors) {
Expand All @@ -131,6 +132,10 @@ export function errorsHashToArray(errors) {
return out;
}

/**
@method errorsArrayToHash
@private
*/
export function errorsArrayToHash(errors) {
let out = {};

Expand Down
8 changes: 5 additions & 3 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ InternalModel.prototype = {
_internalModel: this,
currentState: get(this, 'currentState'),
isError: this.isError,
error: this.error
adapterError: this.error
});
this._triggerDeferredTriggers();
},
Expand Down Expand Up @@ -568,17 +568,19 @@ InternalModel.prototype = {
if (this.record) {
this.record.setProperties({
isError: true,
error: error
adapterError: error
});
}
},

didCleanError: function() {
this.error = null;
this.isError = false;

if (this.record) {
this.record.setProperties({
isError: false,
error: null
adapterError: null
});
}
},
Expand Down
9 changes: 9 additions & 0 deletions packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ var Model = Ember.Object.extend(Ember.Evented, {
return errors;
}).readOnly(),

/**
This property holds the `DS.AdapterError` object with which
last adapter operation was rejected.
@property adapterError
@type {DS.AdapterError}
*/
adapterError: null,

/**
Create a JSON representation of the record, using the serialization
strategy of the store's adapter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ test("if an existing model is edited then deleted, deleteRecord is called on the

test("if a deleted record errors, it enters the error state", function() {
var count = 0;
var error = new DS.AdapterError();

adapter.deleteRecord = function(store, type, snapshot) {
if (count++ === 0) {
return Ember.RSVP.reject();
return Ember.RSVP.reject(error);
} else {
return Ember.RSVP.resolve();
}
Expand All @@ -361,11 +362,13 @@ test("if a deleted record errors, it enters the error state", function() {
return person.save();
})).then(null, async(function() {
equal(tom.get('isError'), true, "Tom is now errored");
equal(tom.get('adapterError'), error, "error object is exposed");

// this time it succeeds
return tom.save();
})).then(async(function() {
equal(tom.get('isError'), false, "Tom is not errored anymore");
equal(tom.get('adapterError'), null, "error object is discarded");
}));
});
});
Expand Down Expand Up @@ -500,15 +503,18 @@ test("if a created record is marked as invalid by the server, you can attempt th
});

test("if a created record is marked as erred by the server, it enters an error state", function() {
var error = new DS.AdapterError();

adapter.createRecord = function(store, type, snapshot) {
return Ember.RSVP.reject();
return Ember.RSVP.reject(error);
};

Ember.run(function() {
var person = store.createRecord('person', { id: 1, name: "John Doe" });

person.save().then(null, async(function() {
ok(get(person, 'isError'), "the record is in the error state");
equal(get(person, 'adapterError'), error, "error object is exposed");
}));
});
});
Expand Down Expand Up @@ -659,8 +665,10 @@ test("if an updated record is marked as invalid by the server, you can attempt t


test("if a updated record is marked as erred by the server, it enters an error state", function() {
var error = new DS.AdapterError();

adapter.updateRecord = function(store, type, snapshot) {
return Ember.RSVP.reject();
return Ember.RSVP.reject(error);
};

var person = run(function() {
Expand All @@ -673,6 +681,7 @@ test("if a updated record is marked as erred by the server, it enters an error s
return person.save();
})).then(null, async(function(reason) {
ok(get(person, 'isError'), "the record is in the error state");
equal(get(person, 'adapterError'), error, "error object is exposed");
}));
});

Expand Down

0 comments on commit 1bea9b7

Please sign in to comment.