Skip to content

Commit

Permalink
[BUGFIX] Change the subclassing in adapter error
Browse files Browse the repository at this point in the history
Fix for: emberjs#5752
  • Loading branch information
Santosh Sutar committed Nov 26, 2018
1 parent 8b7de9e commit 0820c3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
28 changes: 21 additions & 7 deletions addon/-private/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,31 @@ 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 || [
let instance = new EmberError(message);
instance.isAdapterError = true;
instance.errors = errors || [
{
title: 'Adapter Error',
detail: message,
},
];
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
return instance;
}

AdapterError.prototype = Object.create(EmberError.prototype, {
constructor: {
value: EmberError,
enumerable: false,
writable: true,
configurable: true,
},
});

if (Object.setPrototypeOf) {
Object.setPrototypeOf(AdapterError, EmberError);
} else {
AdapterError.__proto__ = EmberError;
}

function extendFn(ErrorClass) {
Expand All @@ -95,16 +111,14 @@ function extendFn(ErrorClass) {
function extend(ParentErrorClass, defaultMessage) {
let ErrorClass = function(errors, message) {
assert('`AdapterError` expects json-api formatted errors array.', Array.isArray(errors || []));
ParentErrorClass.call(this, errors, message || defaultMessage);
return ParentErrorClass.call(this, errors, message || defaultMessage);
};
ErrorClass.prototype = Object.create(ParentErrorClass.prototype);
ErrorClass.extend = extendFn(ErrorClass);

return ErrorClass;
}

AdapterError.prototype = Object.create(EmberError.prototype);

AdapterError.extend = extendFn(AdapterError);

/**
Expand Down
1 change: 0 additions & 1 deletion tests/unit/adapter-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ test('DS.AdapterError', function(assert) {

test('DS.InvalidError', function(assert) {
let error = new DS.InvalidError();

assert.ok(error instanceof Error);
assert.ok(error instanceof DS.AdapterError);
assert.ok(error.isAdapterError);
Expand Down

0 comments on commit 0820c3a

Please sign in to comment.