boxerror: override the properties directly

This commit is contained in:
Girish Ramakrishnan
2021-05-11 17:50:22 -07:00
parent 7dcc904af9
commit 3a252fe10e
2 changed files with 5 additions and 5 deletions

View File

@@ -9,17 +9,17 @@ const assert = require('assert'),
exports = module.exports = BoxError;
function BoxError(reason, errorOrMessage, details) {
function BoxError(reason, errorOrMessage, override) {
assert.strictEqual(typeof reason, 'string');
assert(errorOrMessage instanceof Error || typeof errorOrMessage === 'string' || typeof errorOrMessage === 'undefined');
assert(typeof details === 'object' || typeof details === 'undefined');
assert(typeof override === 'object' || typeof override === 'undefined');
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.reason = reason;
this.details = details || {};
this.details = {};
if (typeof errorOrMessage === 'undefined') {
this.message = reason;
@@ -28,7 +28,7 @@ function BoxError(reason, errorOrMessage, details) {
} else { // error object
this.message = errorOrMessage.message;
this.nestedError = errorOrMessage;
_.extend(this.details, errorOrMessage); // copy enumerable properies
_.extend(this, override); // copy enumerable properies
}
}
util.inherits(BoxError, Error);