2019-09-05 17:13:07 -07:00
|
|
|
/* jslint node:true */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const assert = require('assert'),
|
2019-09-05 21:10:55 -07:00
|
|
|
util = require('util'),
|
|
|
|
|
_ = require('underscore');
|
2019-09-05 17:13:07 -07:00
|
|
|
|
|
|
|
|
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;
|
2019-09-23 23:27:32 -07:00
|
|
|
this.details = details || {};
|
|
|
|
|
|
2019-09-05 17:13:07 -07:00
|
|
|
if (typeof errorOrMessage === 'undefined') {
|
|
|
|
|
this.message = reason;
|
|
|
|
|
} else if (typeof errorOrMessage === 'string') {
|
|
|
|
|
this.message = errorOrMessage;
|
2019-09-23 23:27:32 -07:00
|
|
|
} else { // error object
|
|
|
|
|
this.message = errorOrMessage.message;
|
2019-09-05 17:13:07 -07:00
|
|
|
this.nestedError = errorOrMessage;
|
2019-09-23 23:27:32 -07:00
|
|
|
_.extend(this.details, errorOrMessage); // copy enumerable properies
|
2019-09-05 17:13:07 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
util.inherits(BoxError, Error);
|
|
|
|
|
BoxError.ACCESS_DENIED = 'Access Denied';
|
|
|
|
|
BoxError.ALREADY_EXISTS = 'Already Exists';
|
|
|
|
|
BoxError.BAD_FIELD = 'Bad Field';
|
2019-10-22 20:12:44 -07:00
|
|
|
BoxError.BAD_STATE = 'Bad State';
|
2019-09-06 11:19:58 -07:00
|
|
|
BoxError.COLLECTD_ERROR = 'Collectd Error';
|
2019-09-05 17:13:07 -07:00
|
|
|
BoxError.CONFLICT = 'Conflict';
|
2019-09-06 11:19:58 -07:00
|
|
|
BoxError.DATABASE_ERROR = 'Database Error';
|
|
|
|
|
BoxError.DNS_ERROR = 'DNS Error';
|
|
|
|
|
BoxError.DOCKER_ERROR = 'Docker Error';
|
2019-09-05 17:13:07 -07:00
|
|
|
BoxError.EXTERNAL_ERROR = 'External Error';
|
2019-09-06 11:19:58 -07:00
|
|
|
BoxError.FS_ERROR = 'FileSystem Error';
|
2019-09-05 17:13:07 -07:00
|
|
|
BoxError.INTERNAL_ERROR = 'Internal Error';
|
2019-09-06 11:19:58 -07:00
|
|
|
BoxError.LOGROTATE_ERROR = 'Logrotate Error';
|
|
|
|
|
BoxError.NETWORK_ERROR = 'Network Error';
|
2019-09-05 17:13:07 -07:00
|
|
|
BoxError.NOT_FOUND = 'Not found';
|
2019-09-25 14:13:10 -07:00
|
|
|
BoxError.OPENSSL_ERROR = 'OpenSSL Error';
|
2019-09-06 11:19:58 -07:00
|
|
|
BoxError.REVERSEPROXY_ERROR = 'ReverseProxy Error';
|
2019-09-19 23:13:04 -07:00
|
|
|
BoxError.TASK_ERROR = 'Task Error';
|
2019-09-25 14:13:10 -07:00
|
|
|
BoxError.TRY_AGAIN = 'Try Again';
|
2019-09-21 19:45:55 -07:00
|
|
|
BoxError.UNKNOWN_ERROR = 'Unknown Error'; // only used for porting
|
2019-09-05 21:10:55 -07:00
|
|
|
|
|
|
|
|
BoxError.prototype.toPlainObject = function () {
|
|
|
|
|
return _.extend({}, { message: this.message, reason: this.reason }, this.details);
|
|
|
|
|
};
|