libflitter/errors/HTTPError.js

  1. /**
  2. * @module libflitter/errors/HTTPError
  3. */
  4. const status_codes = require('status-codes')
  5. /**
  6. * An Error class for HTTP response errors.
  7. * @extends Error
  8. */
  9. class HTTPError extends Error {
  10. /**
  11. * Instantiate the error.
  12. * @param {number} status - the HTTP status code
  13. * @param [msg] - the HTTP status message. If not provided, the default message for the status code is used.
  14. */
  15. constructor(status = 500, msg = '') {
  16. status = status_codes[status]
  17. super(msg ? msg : status.message)
  18. this.http_status = status
  19. this.status = status.status
  20. }
  21. }
  22. module.exports = exports = HTTPError
JAVASCRIPT
Copied!