Comparing version 0.26.0 to 0.27.0
{ | ||
"name": "middy", | ||
"version": "0.26.0", | ||
"version": "0.27.0", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -23,2 +23,21 @@ const middy = require('../../middy') | ||
test('It should create a response for HTTP errors created with a generic error', () => { | ||
const handler = middy((event, context, cb) => { | ||
const err = new Error('A server error') | ||
err.statusCode = 500 | ||
throw err | ||
}) | ||
handler | ||
.use(httpErrorHandler({ logger: false })) | ||
// run the handler | ||
handler({}, {}, (_, response) => { | ||
expect(response).toEqual({ | ||
statusCode: 500, | ||
body: 'A server error' | ||
}) | ||
}) | ||
}) | ||
test('It should NOT handle non HTTP errors', () => { | ||
@@ -25,0 +44,0 @@ const handler = middy((event, context, cb) => { |
@@ -10,3 +10,5 @@ module.exports = (opts) => { | ||
onError: (handler, next) => { | ||
if (handler.error.constructor.super_ && handler.error.constructor.super_.name === 'HttpError') { | ||
// if there are a `statusCode` and an `error` field | ||
// this is a valid http error object | ||
if (handler.error.statusCode && handler.error.message) { | ||
if (typeof options.logger === 'function') { | ||
@@ -13,0 +15,0 @@ options.logger(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
182345
4595