js-exceptions
v1.2.0
Published
Nodejs Exception Handler
Downloads
51
Maintainers
Readme
JS-EXCEPTIONS
Nodejs Exception Handler - Usable anywhere!
Error handling is core to any stable and reliable solution mostly a REST API. I use this solution in all of my Nodejs - Express projects It never disappoints!
npm install js-exceptions
import { HttpException } from "js-exceptions";
throw new HttpException("Internal Server Error", 500);
HttpException is the core exception - all other type of exceptions extends it and you can use it directly
import {
HttpException,
NotFoundException,
UnauthorizedException,
} from "js-exceptions";
throw new UnauthorizedException("Your are not allowed!");
HttpException can be used to extend your error-handling needs
import { HttpException, HttpCodes } from "js-exceptions";
class ForbiddenException extends HttpException {
status_code: HttpCodes = 403;
}
throw new ForbiddenException("Private resource");
class ForbiddenException extends HttpException {
status_code: HttpCodes = 403;
constructor(resource: string) {
super(`${resource} is private`);
}
}
throw new ForbiddenException("Book");