let util = require('util'),
http = require('http');
function HttpError(status, message) {
Error.apply(this, arguments);
Error.captureStackTrace(this, HttpError);
this.status = status;
this.message = message || http.STATUS_CODES[status] || "Error";
}
util.inherits(HttpError, Error);
HttpError.prototype.name = 'HttpError';
exports.HttpError = HttpError;
'use strict';
const { STATUS_CODES } = require('http');
// https://nodejs.org/api/esm.html#esm_enabling
// import { STATUS_CODES } from 'http';
class HttpError extends Error {
constructor(status, message=STATUS_CODES[status]) {
super(message);
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
// this.status = status;
// https://nodejs.org/api/errors.html#errors_error_code
this.code = status;
this.message = message || 'Error';
}
}
module.exports = HttpError;
// export default HttpError;
import util from 'util';
import http from 'http';
function HttpError(status, message) {
Error.apply(this, arguments);
Error.captureStackTrace(this, HttpError);
this.status = status;
this.message = message || http.STATUS_CODES[status] || "Error";
}
util.inherits(HttpError, Error);
HttpError.prototype.name = 'HttpError';
export {HttpError};