courtbot-engine
Version:
An engine for courtbot-like functionality to be included in city/county services sites.
51 lines (34 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/* Module containing an extension of the Error class for courtbot-specific purposes */
// See https://www.bennadel.com/blog/2828-creating-custom-error-objects-in-node-js-with-error-capturestacktrace.htm
var COURTBOT_ERROR_NAME = exports.COURTBOT_ERROR_NAME = 'Courtbot Error';
var API = Object.freeze({ 'GENERAL': 'api-error--general', 'GET': 'api-error--get' });
var COURTBOT_ERROR_TYPES = exports.COURTBOT_ERROR_TYPES = Object.freeze({ 'API': API });
var courtbotError = function (_Error) {
_inherits(courtbotError, _Error);
function courtbotError() {
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var context = arguments[1];
_classCallCheck(this, courtbotError);
var _this = _possibleConstructorReturn(this, (courtbotError.__proto__ || Object.getPrototypeOf(courtbotError)).call(this));
settings = settings || {};
_this.name = COURTBOT_ERROR_NAME;
_this.type = settings.type || 'general';
_this.message = settings.message || 'No message listed';
_this.case = settings.case || 'No case listed';
_this.api = settings.api || 'No api listed';
_this.timestamp = settings.timestamp || 'No timestamp listed';
_this.initialError = settings.initialError || null;
_this.isCourtbotError = true; // undefined values are falsy
Error.captureStackTrace(_this, context || courtbotError);
return _this;
}
return courtbotError;
}(Error);
exports.default = courtbotError;