Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Created September 22, 2020 19:47
Show Gist options
  • Select an option

  • Save anushshukla/96dd6323f978e4dc491296142b2cd294 to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/96dd6323f978e4dc491296142b2cd294 to your computer and use it in GitHub Desktop.
JavaScript Custom Error (HTTP)
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