New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express_cowrap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express_cowrap

co-wrap function to use proper error handling and easier asynchronous operations (by using generators) with Express

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status Code Climate Issue Count Test Coverage

express_cowrap

Wraps Express middleware functions so you can use proper error handling for applications depending heavily on Promises. Examples:


const Promise = require('bluebird')
const coWrap = require('express_cowrap')
const express = require('express')

let app = express()

// Promise-returing function
app.get('/promise', coWrap(function (req, res) {
    return Promise.reject('error message')
})

// Regular, synchronous function
app.get('/sync', coWrap(function (req, res) {
    throw new Error('error message')
}))

// Generator function (with yield)
app.get('/generators', coWrap(function* (req, res) {
    let data = yield database.query() // promise-returning function
    yield Promise.delay(20)
    
    throw new Error('error message')
    
    // Won't execute this
    res.status(200).send({ message: "You won't see me!" })
}))

// Error handler
app.use(function errorHandler(err, req, res, next) {
    console.log('[Error happened]', err)
    
    res.status(500).send({ error: (err.message || err) })
})

Keywords

FAQs

Package last updated on 24 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc