Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename error attribute #3534

Merged
merged 2 commits into from
Jul 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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