1.2.5 • Published 1 year ago

express-exception v1.2.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Express-Exception

Express exception is an plug-and-play package for handling HTTP exceptions in your express application. It is very easy to install and use. It will provide you with next level of exceptions handling in a seamless way.

Installation

Use the yarn or npm to install express-exception.

npm install express-exception

or

yarn add express-exception

Usage

import express from 'express';
import expressException from 'express-exception';

const app = express();

app.use(express.json());
//rest of your middlewares or routes

//set express-exception to handle your exceptions
expressException.setHandler(app);

app.listen(3000, ()=>{
console.log(`Application started on port ${3000}`);
}

Example Implementation

import express, { Request, Response } from 'express';
import ee, { CustomHttpException, InternalServerErrorException, NotFoundException } from 'express-exception';

const app = express();

app.use(express.json())

app.get('/', (_req: Request, _res: Response) => {
  //custom exception from 'express-exception'
  throw new CustomHttpException('Custom Error Message', 500)
})

app.get('/404', (_req: Request, _res: Response) => {
  //not found exception from 'express-exception'
  throw new NotFoundException()
})

app.get('/500', (_req: Request, _res: Response) => {
  //server error from 'express-exception'
  throw new InternalServerErrorException()
})

app.get('/other', (_req: Request, _res: Response) => {
  //some other Unhandled error that 'express-exception' will handle
  throw new Error('Some other Unhandled Error')
})

ee.setHandler(app)
app.listen(5000, () => {
  console.log('App started listening on port 5000')
})
1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago