Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

error-handler-e2

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-handler-e2

This is handle error package

  • 4.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Error Handler E2

npm version  https://img.shields.io/npm/dm/error-handler-e2.svg Build Status npm version 

This is a common page for:

  • Error handler
  • Http Status codes
  1. Installation
  2. Usage
  3. Options

Installation

npm i error-handler-e2
// Or 
yarn add error-handler-e2

Usage

const { Errors: { BadRequestError } } = require('error-handler-e2');
// or
import { Errors } from 'error-handler-e2'

Options

  1. Errors

BadRequestError

const { Errors:{ BadRequestError }} = require('error-handler-e2');

throw new BadRequestError('Bad request error message', { time: new Date() });

ConflictError

const { Errors:{ ConflictError }} = require('error-handler-e2');

throw new ConflictError('conflict error message', { time: new Date() });

CustomError

const { Errors:{ CustomError }} = require('error-handler-e2');

throw new CustomError('Custom error message', { time: new Date() });

DatabaseError

const { Errors:{ DatabaseError }} = require('error-handler-e2');

throw new DatabaseError('Database error message', { time: new Date() });

InternalServerError

const { Errors:{ InternalServerError }} = require('error-handler-e2');

throw new InternalServerError('Internal Server error message', { time: new Date() });

NoContentError

const { Errors:{ NoContentError }} = require('error-handler-e2');

throw new NoContentError('NoContent error message', { time: new Date() });

NotFoundError

const { Errors:{ NotFoundError }} = require('error-handler-e2');

throw new NotFoundError('NotFound error message', { time: new Date() });

UnAuthenticatedError

const { Errors:{ UnAuthenticatedError }} = require('error-handler-e2');

throw new UnAuthenticatedError('UnAuthenticated error message', { time: new Date() });

UnAuthorizedError

const { Errors:{ UnAuthorizedError }} = require('error-handler-e2');

throw new UnAuthorizedError('UnAuthorized error message', { time: new Date() });

UnProcessableEntityError

const { Errors:{ UnProcessableEntityError }} = require('error-handler-e2');

throw new UnProcessableEntityError('UnProcessable Entity error message', { time: new Date() });
  1. Http Status

NO_CONTENT 204

const { StatusCodes: { NO_CONTENT } } = require('error-handler-e2');

BAD_REQUEST 400

const { StatusCodes: { BAD_REQUEST } } = require('error-handler-e2');

UNAUTHENTICATED 401

const { StatusCodes: { UNAUTHENTICATED } } = require('error-handler-e2');

UNAUTHORIZED 403

const { StatusCodes: { UNAUTHORIZED } } = require('error-handler-e2');

NOT_FOUND 404

const { StatusCodes: { NOT_FOUND } } = require('error-handler-e2');

CONFLICT 409

const { StatusCodes: { CONFLICT } } = require('error-handler-e2');

UNPROCURABLE_ENTITY 422

const { StatusCodes: { UNPROCURABLE_ENTITY } } = require('error-handler-e2');

INTERNAL_SERVER_ERROR 500

const { StatusCodes: { INTERNAL_SERVER_ERROR } } = require('error-handler-e2');
  1. Middleware

loggerMiddleware


const { Middleware:{ loggerMiddleware }} = require('error-handler-e2');

app.use(loggerMiddleware);

handleErrorMiddleware


const { Middleware:{ handleErrorMiddleware }} = require('error-handler-e2');

app.use(handleErrorMiddleware);

handleErrorMiddleware


const { Middleware:{ notFoundMiddleware }} = require('error-handler-e2');

app.use(notFoundMiddleware);

asyncHandlerMiddleware

import { Middleware:{ asyncHandlerMiddleware }, StatusCodes } from 'error-handler-e2';

// get users example
route.get('/users', asyncHandler(async (req: Request, res: Response, next: NextFunction) => {

    return res.status(StatusCodes.OK).json({ users: [{ id: 1, name: 'Milad' } ]});
  })
);

Keywords

FAQs

Package last updated on 09 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc