1.2.0 • Published 6 months ago

js-exceptions v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

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");

Please Join Me and We better this solution,

Thank You

1.2.0

6 months ago

1.1.0

8 months ago

1.0.0

8 months ago