libflitter/errors/HTTPError.js

/**
 * @module libflitter/errors/HTTPError
 */

const status_codes = require('status-codes')

/**
 * An Error class for HTTP response errors.
 * @extends Error
 */
class HTTPError extends Error {
    /**
     * Instantiate the error.
     * @param {number} status - the HTTP status code
     * @param [msg] - the HTTP status message. If not provided, the default message for the status code is used.
     */
    constructor(status = 500, msg = '') {
        status = status_codes[status]
        super(msg ? msg : status.message)
        this.http_status = status
        this.status = status.status
    }
}

module.exports = exports = HTTPError