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
+4 -4
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);
+1 -1
View File
@@ -93,7 +93,7 @@ function query() {
const callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
args.push(function queryCallback(error, result) {
if (error) return callback ? callback(error) : reject(new BoxError(BoxError.DATABASE_ERROR, error));
if (error) return callback ? callback(error) : reject(new BoxError(BoxError.DATABASE_ERROR, error, { code: error.code, sqlMessage: error.sqlMessage }));
callback ? callback(null, result) : resolve(result);
});