@mcrowe/safe-async-express-errors
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Safe Async Express Errors

Typesafe wrapper around async express handlers that ensures that asynchronous errors are caught and handled by error-handling middleware.

This module can be used in either Javascript or Typescript, but is most useful for Typescript projects because it makes an effort to preserve type safety for the compiler (unlike other solutions).

Usage

npm install @mcrowe/safe-async-express-errors --save

Then wrap any asynchronous express handler functions:

const safe = require('@mcrowe/safe-async-express-errors')
// ...

// Errors thrown by `db.many` will now be handled by any middleware you've setup,
// instead of swallowed.
app.get('/', safe(async (req, res) => {
  const things = await db.many('SELECT * FROM things')
  res.json({ things })
}))

Development

Install npm modules:

npm install

Run tests:

npm test

Build:

npm run build

Publish to npm:

  1. Update the version in package.json

  2. Build using npm run build

  3. Publish using npm publish --access=public

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    2,661
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    2,661
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i @mcrowe/safe-async-express-errors

Weekly Downloads

2,661

Version

0.0.3

License

ISC

Last publish

Collaborators

  • mcrowe