throw-http-errors
Version:
Custom errors for HTTP status codes.
22 lines (21 loc) • 820 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateCustomError = void 0;
const isErrorStatus = (status) => status >= 400 && status < 600;
// eslint-disable-next-line import/prefer-default-export
class CreateCustomError extends Error {
constructor(status, name, message, code) {
super(message);
if (!isErrorStatus(status)) {
throw new TypeError('status is not of valid http status number');
}
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = name || 'CustomError';
this.status = status;
this.message = message || 'Custom Error without message';
this.code = code || 'CUSTOM_ERROR';
}
}
exports.CreateCustomError = CreateCustomError;