npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

custom-error-handlers

v2.0.0

Published

custom error in a simple way

Downloads

11

Readme

Custom Error

A Custom Error library for daily use With Error handler

Installation

  npm install custom-error-handlers

Step

1.Import Custom Error and handler
2.Add Error handler in the app
3.Throw Error
4.That much simple

Usage/Examples

1) Import

  • All Error Class are in the custom-error-handlers/error folder
//import Error Class seperately
const {
  AuthenticationError,
} = require('custom-error-handlers/error');
const { AuthorizationError } = require('custom-error-handlers/error');
const { BadRequestError } = require('custom-error-handlers/error');
const { ConfigurationError } = require('custom-error-handlers/error');
const { ControllerError } = require('custom-error-handlers/error');
const { DatabaseError } = require('custom-error-handlers/error');
const { NotFoundError } = require('custom-error-handlers/error');
const { PermissionError } = require('custom-error-handlers/error');
const { ValidationError } = require('custom-error-handlers/error');
//import Error Class as needed
const {
  AuthenticationError,
  NotFoundError,
  ValidationError,
} = require('custom-error-handlers/error');
//import all Error Class together
const Error = require('custom-error-handlers/error');
  • Import Error Middleware
const { CustomErrorHandler } = require('custom-error-handlers');

2) Use Error Middleware

Note add this line after using all router and Middleware

app.use(CustomErrorHandler()); //using custom-error-handlers handler

3) Throw CustomError

now throw custom error from any Middleware, Controller or Handler

throw new NotFoundError(); //for not found error

4) Nothing more you have implemented Custom Error Successfully

API Reference

CustomError

| Parameter | Type | Description | | :------------- | :------- | :----------------------------------- | | errorName | string | for identifying error type | | errorMessage | string | for error message | | statusCode | number | for sending error code to the client | | errorCode | string | for identifing specific error |

All other Error Class

Note there is no errorName Parameter in these Error Class, they are already set for use

| Parameter | Type | Description | | :------------- | :------- | :----------------------------------- | | errorMessage | string | for error message | | statusCode | number | for sending error code to the client | | errorCode | string | for identifing specific error |

Error Handling Middleware

| Parameter | Type | Default | Description | | :--------------------- | :-------- | :------ | :------------------------------- | | options | Object | | configure the middleware | | options.passControl | boolean | false | should call next() | | options.sendResponse | boolean | true | should send response to client |

Default errorMessage and statusCode

| Class | errorMessage | statusCode | | :-------------------- | :---------------------- | :--------- | | AuthenticationError | Permission Needed | 403 | | AuthorizationError | Unauthorized | 401 | | BadRequestError | Bad Request | 400 | | ConfigurationError | Internal Server Error | 500 | | ControllerError | Internal Server Error | 500 | | CustomError | Internal Server Error | 500 | | DatabaseError | Service Unavailable | 503 | | NotFoundError | Not Found | 404 | | PermissionError | Permission Needed | 403 | | ValidationError | Bad Request | 400 |

Note all CustomError other than CustomError itself extends to CustomError which extends to Error

You can create new CustomError Class as you need by extending CustomError Class

Author

@github-MHRSRoni
@Mail me