Skip to content

Instantly share code, notes, and snippets.

@kluu1
Created April 2, 2020 13:04
Show Gist options
  • Select an option

  • Save kluu1/e2a37b40c59d255456327a4e8ec33738 to your computer and use it in GitHub Desktop.

Select an option

Save kluu1/e2a37b40c59d255456327a4e8ec33738 to your computer and use it in GitHub Desktop.
class GeneralError extends Error {
constructor(message) {
super();
this.message = message;
}
getCode() {
if (this instanceof BadRequest) {
return 400;
} if (this instanceof NotFound) {
return 404;
}
return 500;
}
}
class BadRequest extends GeneralError { }
class NotFound extends GeneralError { }
module.exports = {
GeneralError,
BadRequest,
NotFound
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment