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

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.10.10 to 0.11.0

7

middlewares.d.ts
import { SSM } from 'aws-sdk'
import { Options as AjvOptions } from 'ajv'
import { HttpError } from 'http-errors'
import middy from './src/middy'

@@ -35,2 +36,6 @@

interface IHTTPErrorHandlerOptions {
logger?: (error: HttpError) => void;
}
interface IHTTPHeaderNormalizerOptions {

@@ -70,3 +75,3 @@ normalizeHeaderKey?: (key: string) => string;

declare function httpContentNegotiation(opts?: IHTTPContentNegotiationOptions): middy.IMiddyMiddlewareObject;
declare function httpErrorHandler(): middy.IMiddyMiddlewareObject;
declare function httpErrorHandler(opts?: IHTTPErrorHandlerOptions): middy.IMiddyMiddlewareObject;
declare function httpEventNormalizer(): middy.IMiddyMiddlewareObject;

@@ -73,0 +78,0 @@ declare function httpHeaderNormalizer(opts?: IHTTPHeaderNormalizerOptions): middy.IMiddyMiddlewareObject;

8

package.json
{
"name": "middy",
"version": "0.10.10",
"version": "0.11.0",
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda",

@@ -17,2 +17,3 @@ "main": "./index.js",

"test:lint": "eslint --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .",
"test:typings": "typings-tester --config tsconfig.json index.d.ts middlewares.d.ts",
"test:unit": "jest --verbose --coverage",

@@ -62,6 +63,9 @@ "test:unit:watch": "jest --verbose --coverage --watch",

"marked": "^0.3.12",
"regenerator-runtime": "^0.11.0"
"regenerator-runtime": "^0.11.0",
"typescript": "^2.8.1",
"typings-tester": "^0.3.1"
},
"dependencies": {
"@types/aws-lambda": "^0.0.34",
"@types/http-errors": "^1.6.1",
"ajv": "^6.0.0",

@@ -68,0 +72,0 @@ "ajv-keywords": "^3.0.0",

@@ -12,3 +12,3 @@ const middy = require('../../middy')

handler
.use(httpErrorHandler())
.use(httpErrorHandler({ logger: false }))

@@ -30,3 +30,3 @@ // run the handler

handler
.use(httpErrorHandler())
.use(httpErrorHandler({ logger: false }))

@@ -39,2 +39,19 @@ // run the handler

})
test('It should be possible to pass a custom logger function', () => {
const expectedError = new createError.UnprocessableEntity()
const logger = jest.fn()
const handler = middy((event, context, cb) => {
throw expectedError
})
handler
.use(httpErrorHandler({ logger }))
// run the handler
handler({}, {}, (_, response) => {
expect(logger).toHaveBeenCalledWith(expectedError)
})
})
})

@@ -1,16 +0,26 @@

const { HttpError } = require('http-errors')
module.exports = (opts) => {
const defaults = {
logger: console.error
}
module.exports = () => ({
onError: (handler, next) => {
if (handler.error instanceof HttpError) {
handler.response = {
statusCode: handler.error.statusCode,
body: handler.error.message
const options = Object.assign({}, defaults, opts)
return ({
onError: (handler, next) => {
if (handler.error.constructor.super_ && handler.error.constructor.super_.name === 'HttpError') {
if (typeof options.logger === 'function') {
options.logger(handler.error)
}
handler.response = {
statusCode: handler.error.statusCode,
body: handler.error.message
}
return next()
}
return next()
return next(handler.error)
}
return next(handler.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