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

[BUGFIX CHORE] Change the subclassing in adapter error #5759

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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