Comparing version 0.10.10 to 0.11.0
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; |
{ | ||
"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) | ||
} | ||
}) | ||
}) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119292
2840
4
10
18
+ Added@types/http-errors@^1.6.1
+ Added@types/http-errors@1.8.2(transitive)