npm.io
3.0.0 • Published 6 years ago

sung-error-handler

Licence
ISC
Version
3.0.0
Deps
4
Size
12 kB
Vulns
0
Weekly
0

Sung Error Handler

sung-error-handler is a Typescript library to handle error in an eloquent manner

Installation

Use the package manager npm to install foobar.

npm install --save sung-error-handler

Usage

import {errorHandler} from "sung-error-handler" 

const app = express()


app.use(errorHandler)
import {BadRequestError} from "sung-error-handler" 

app.post("/apis/tickets", async (req: Request, res: Response) => {
   try{
       axios.post("")
      //your business logic
    }
  catch(err){
     throw new BadRequestError("custom message")
  }
})
import {BadRequestError, DatabaseConnectionError, NotFoundError} from "sung-error-handler" 

app.post("/apis/tickets", async (req: Request, res: Response) => {
   try{
       axios.post("")
      //your business logic
    }
  catch(err){
     throw new NotFoundError()
  }
})

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT