Skip to content

Instantly share code, notes, and snippets.

@commenthol
Created July 15, 2018 18:28
Show Gist options
  • Save commenthol/5d41250c684e8c3717ddbb5bcb2717f6 to your computer and use it in GitHub Desktop.
Save commenthol/5d41250c684e8c3717ddbb5bcb2717f6 to your computer and use it in GitHub Desktop.
http error
const {STATUS_CODES} = require('http')
/**
* HTTP Error
* @param {Number} status - http status code
* @param {String|Error} msg - message or error
* @param {String} [code] - optional code
* @return {Error} error
*/
const httpError = (status = 500, msg, code) => {
msg = msg || STATUS_CODES[status]
const err = msg instanceof Error ? msg : new Error(msg)
err.status = status
if (code) err.code = code
return err
}
module.exports = httpError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment