|
|
|
@ -11,6 +11,13 @@ const forbidSpecialProperties = require("./validators/forbid-special-properties"
|
|
|
|
|
const isErrorConstructor = require("./validators/is-error-constructor");
|
|
|
|
|
const isContextSchema = require("./validators/is-context-schema");
|
|
|
|
|
|
|
|
|
|
function safeAssign(a, ... rest) {
|
|
|
|
|
let previousPrototype = a.__proto__;
|
|
|
|
|
Object.assign(a, ... rest);
|
|
|
|
|
a.__proto__ = previousPrototype;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function createCustomErrorType(_name, _options) {
|
|
|
|
|
let [ name, options ] = validateArguments(arguments, {
|
|
|
|
|
name: [ required, isString ],
|
|
|
|
@ -48,7 +55,7 @@ module.exports = function createCustomErrorType(_name, _options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorConstructor._assignDefaultProperties(this);
|
|
|
|
|
Object.assign(this, context);
|
|
|
|
|
safeAssign(this, context);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ErrorConstructor._assignDefaultProperties = function (errorObject) {
|
|
|
|
@ -58,7 +65,7 @@ module.exports = function createCustomErrorType(_name, _options) {
|
|
|
|
|
options.inheritsFrom._assignDefaultProperties(errorObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.assign(errorObject, options.context);
|
|
|
|
|
safeAssign(errorObject, options.context);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ErrorConstructor.prototype = Object.create(options.inheritsFrom.prototype);
|
|
|
|
|