Created
July 15, 2018 18:28
-
-
Save commenthol/5d41250c684e8c3717ddbb5bcb2717f6 to your computer and use it in GitHub Desktop.
http error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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