1.0.6 • Published 4 years ago

gc-express-controller-wrapper v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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)
    }
  })
1.0.6

4 years ago

1.0.5

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago