gc-express-controller-wrapper

1.0.6 • Public • Published

Gc-Express-controller-wrapper

This little library automatically wraps your controller functions into a try catch block and calls the next function when an error occurs with the thrown error data.

Installation

npm install gc-express-controller-wrapper

Usage

  routes.get('/error', controllerUtil(async (_req, res) => {
    const requestData = (await axios.get('https://jsonplaceholder.typicode.com/todos/a')).data
    return res.json({...requestData})
  }))

Usage without express-controller-wrapper

  routes.get('/', async (_req, res, next) => {
    try {
      const requestData = (await axios.get('https://jsonplaceholder.typicode.com/todos/1')).data
      return res.json({...requestData})
    } catch(err) {
      next(err)
    }
  })

Readme

Keywords

none

Package Sidebar

Install

npm i gc-express-controller-wrapper

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

3.99 kB

Total Files

6

Last publish

Collaborators

  • thomassimon