Skip to content

Commit

Permalink
[BUGFIX beta] Add ducktyping of AdapterError
Browse files Browse the repository at this point in the history
There are `instanceof` checks for `AdapterError` this removes them in
favor of checking for a property on the error, `isAdapterError` appears
on all errors that use `AdapterError` as the base.
  • Loading branch information
danmcclain committed Jan 27, 2016
1 parent c540db1 commit ee7bc80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions addon/-private/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
@namespace DS
*/
export function AdapterError(errors, message = 'Adapter operation failed') {
this.isAdapterError = true;
EmberError.call(this, message);

this.errors = errors || [
Expand Down
2 changes: 1 addition & 1 deletion addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ export default Adapter.extend(BuildURLMixin, {
requestData
);

if (response instanceof AdapterError) {
if (response && response.isAdapterError) {
Ember.run.join(null, reject, response);
} else {
Ember.run.join(null, resolve, response);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/adapter-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ test("DS.AdapterError", function(assert) {
var error = new DS.AdapterError();
assert.ok(error instanceof Error);
assert.ok(error instanceof Ember.Error);
assert.ok(error.isAdapterError);
});

test("DS.InvalidError", function(assert) {
var error = new DS.InvalidError();
assert.ok(error instanceof Error);
assert.ok(error instanceof DS.AdapterError);
assert.ok(error.isAdapterError);
});

test("DS.TimeoutError", function(assert) {
var error = new DS.TimeoutError();
assert.ok(error instanceof Error);
assert.ok(error instanceof DS.AdapterError);
assert.ok(error.isAdapterError);
});

test("DS.AbortError", function(assert) {
var error = new DS.AbortError();
assert.ok(error instanceof Error);
assert.ok(error instanceof DS.AdapterError);
assert.ok(error.isAdapterError);
});

var errorsHash = {
Expand Down

0 comments on commit ee7bc80

Please sign in to comment.