Created
September 22, 2020 19:47
-
-
Save anushshukla/96dd6323f978e4dc491296142b2cd294 to your computer and use it in GitHub Desktop.
JavaScript Custom Error (HTTP)
This file contains hidden or 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
| function HttpError( | |
| message = 'Unknown', | |
| status = 500, | |
| code = 'InternalServerError' | |
| ) { | |
| this.name = "HttpError"; | |
| this.status = status; | |
| this.code = code; | |
| this.message = message; | |
| this.success = false; | |
| this.toJSON = () => ({ | |
| message: this.message, | |
| success: this.success, | |
| code: this.code, | |
| }) | |
| } | |
| HttpError.prototype = Error.prototype; | |
| module.exports = HttpError; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment