JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q56883F
  • License ISC

Async middleware to handle errors

Package Exports

  • escape-try-catch
  • escape-try-catch/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (escape-try-catch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Escape-Try-Catch

Escape-Try-Catch is an npm package that helps you escape the traditional try-catch mechanism. It allows you to write code freely without worrying about handling errors in your async calls.

The latest versions also include MS Teams Middleware, enabling you to send alerts to a Teams channel effortlessly.

Installation

Use the npm package manager to install foobar.

npm install escape-try-catch

Usage

const { asyncMiddleware } = require("escape-try-catch")


# Use it like this inside your routes
router.get('/test', asyncMiddleware(getUser))

# your controller function looks like this
getUser: async function(req,res) {
    let users = User.find({})
    res.send(users)
}


# Any error that occurs in the above function will be handled by the middleware

Async Teams Middleware

You can use this same as Async middleware . This middleware will send an alert on teams as if it catches a error in a request . In here you need to sepcify the following details like this

const { asyncTeamsErrorMiddleware } = require("escape-try-catch")


# Use it like this inside your routes
router.get('/test', asyncTeamsErrorMiddleware(getUser,options))

# your controller function looks like this
getUser: async function(req,res) {
    let users = User.find({})
    res.send(users)
}
# Options is the config object. In which you can specify various configurations
# it includes
{MS_TEAM_WEBHOOK_URL: "Need to pass the url for you chat this you can get from teams", "ENV": "Prod"}

# Any error that occurs in the above function will be handled by the middleware

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