From 1599f8757b7ed5446cfcc80e053a1c42368fa46f Mon Sep 17 00:00:00 2001 From: tchak Date: Sun, 12 Jul 2015 11:53:17 +0200 Subject: [PATCH 1/2] fix documentation warnings --- packages/ember-data/lib/adapters/errors.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/ember-data/lib/adapters/errors.js b/packages/ember-data/lib/adapters/errors.js index df8cb6954dc..b4ca080242d 100644 --- a/packages/ember-data/lib/adapters/errors.js +++ b/packages/ember-data/lib/adapters/errors.js @@ -108,6 +108,7 @@ export function AbortError() { AbortError.prototype = Object.create(AdapterError.prototype); /** + @method errorsHashToArray @private */ export function errorsHashToArray(errors) { @@ -131,6 +132,10 @@ export function errorsHashToArray(errors) { return out; } +/** + @method errorsArrayToHash + @private +*/ export function errorsArrayToHash(errors) { let out = {}; From 687fc9fb8371d55926100f26b597fe8a3f07c5d1 Mon Sep 17 00:00:00 2001 From: tchak Date: Sun, 12 Jul 2015 12:05:30 +0200 Subject: [PATCH 2/2] [BUGFIX release] Rename `error` to `adapterError` Closes #3449 --- .../ember-data/lib/system/model/internal-model.js | 8 +++++--- packages/ember-data/lib/system/model/model.js | 9 +++++++++ .../integration/adapter/store-adapter-test.js | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/ember-data/lib/system/model/internal-model.js b/packages/ember-data/lib/system/model/internal-model.js index b68aeec819e..d752fa9c646 100644 --- a/packages/ember-data/lib/system/model/internal-model.js +++ b/packages/ember-data/lib/system/model/internal-model.js @@ -113,7 +113,7 @@ InternalModel.prototype = { _internalModel: this, currentState: get(this, 'currentState'), isError: this.isError, - error: this.error + adapterError: this.error }); this._triggerDeferredTriggers(); }, @@ -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 }); } }, diff --git a/packages/ember-data/lib/system/model/model.js b/packages/ember-data/lib/system/model/model.js index fcf17395cc6..5c0949d29ea 100644 --- a/packages/ember-data/lib/system/model/model.js +++ b/packages/ember-data/lib/system/model/model.js @@ -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. diff --git a/packages/ember-data/tests/integration/adapter/store-adapter-test.js b/packages/ember-data/tests/integration/adapter/store-adapter-test.js index a57cb647806..b8dd302eedb 100644 --- a/packages/ember-data/tests/integration/adapter/store-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/store-adapter-test.js @@ -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(); } @@ -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"); })); }); }); @@ -500,8 +503,10 @@ 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() { @@ -509,6 +514,7 @@ test("if a created record is marked as erred by the server, it enters an error s 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"); })); }); }); @@ -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() { @@ -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"); })); });