boxerror: override the properties directly
This commit is contained in:
+4
-4
@@ -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
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user