Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-async-handler

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-async-handler - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

.travis.yml

9

index.d.ts

@@ -1,1 +0,8 @@

declare module 'express-async-handler'
import express = require('express');
declare function expressAsyncHandler(handler: express.RequestHandler): express.RequestHandler;
declare namespace expressAsyncHandler {
}
export = expressAsyncHandler;

6

index.js
const asyncUtil = fn =>
function asyncUtilWrap(req, res, next, ...args) {
const fnReturn = fn(req, res, next, ...args)
if (fnReturn instanceof Promise) {
return fnReturn.catch(next)
} else {
return fnReturn
}
return Promise.resolve(fnReturn).catch(next)
}
module.exports = asyncUtil
{
"name": "express-async-handler",
"version": "1.1.1",
"version": "1.1.2",
"description": "Express Error Handler for Async Functions",

@@ -23,2 +23,5 @@ "main": "index.js",

"license": "MIT",
"dependencies": {
"@types/express": "*"
},
"devDependencies": {

@@ -25,0 +28,0 @@ "chai": "^4.1.2",

@@ -75,2 +75,27 @@ const chai = require('chai')

})
// NB, thenables are not guaranteed to have a `catch` method.
it('should handle thenables', async () => {
const error = Error('catch me!')
// construct a minimalist thenable which we can fail at a specific time
let thenable, triggerFailure
const registeringThenable = new Promise(res => {
thenable = {
then: sinon.spy((success, fail) => {
triggerFailure = fail
res()
})
}
})
// test the actual library feature
const next = sinon.spy()
const catchingThenable = asyncUtil(_ => thenable)(null, null, next)
await registeringThenable
expect(thenable.then).to.have.been.called
expect(next).not.to.have.been.called
triggerFailure(error)
await catchingThenable
expect(next).to.have.been.calledWith(error)
})
})
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