Use BoxError for apptask errors

This commit is contained in:
Girish Ramakrishnan
2019-09-05 17:13:07 -07:00
parent e10a6d9de5
commit 99e63ffc3f
2 changed files with 60 additions and 16 deletions
+38
View File
@@ -0,0 +1,38 @@
/* jslint node:true */
'use strict';
const assert = require('assert'),
util = require('util');
exports = module.exports = BoxError;
function BoxError(reason, errorOrMessage, details) {
assert.strictEqual(typeof reason, 'string');
assert(errorOrMessage instanceof Error || typeof errorOrMessage === 'string' || typeof errorOrMessage === 'undefined');
assert(typeof details === 'object' || typeof details === 'undefined');
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.reason = reason;
if (typeof errorOrMessage === 'undefined') {
this.message = reason;
} else if (typeof errorOrMessage === 'string') {
this.message = errorOrMessage;
} else {
this.message = 'Internal error';
this.nestedError = errorOrMessage;
}
this.details = details || {};
}
util.inherits(BoxError, Error);
BoxError.ACCESS_DENIED = 'Access Denied';
BoxError.ALREADY_EXISTS = 'Already Exists';
BoxError.BAD_FIELD = 'Bad Field';
BoxError.CONFLICT = 'Conflict';
BoxError.EXTERNAL_ERROR = 'External Error';
BoxError.INTERNAL_ERROR = 'Internal Error';
BoxError.NOT_FOUND = 'Not found';