@middy/core
Advanced tools
Comparing version 1.0.0-beta.10 to 1.0.0-beta.11
@@ -709,2 +709,63 @@ const middy = require('../') | ||
// see issue #485 https://github.com/middyjs/middy/issues/485 | ||
test('It will keep invoking all the onError handlers if one of them resolves to a falsy value', (endTest) => { | ||
const handler = middy((event, context) => { | ||
throw new Error('something bad happened') | ||
}) | ||
const middleware1 = { | ||
onError: (handler) => { | ||
handler.response = { error: handler.error } | ||
return Promise.resolve() | ||
} | ||
} | ||
const middleware2 = { | ||
onError: (handler) => { | ||
handler.response.middleware2_called = true | ||
return Promise.resolve(handler.error) | ||
} | ||
} | ||
handler | ||
.use(middleware1) | ||
.use(middleware2) | ||
handler({}, {}, (err, response) => { | ||
expect(err).toBeNull() | ||
expect(response.middleware2_called).toBeTruthy() | ||
endTest() | ||
}) | ||
}) | ||
// see issue #485 https://github.com/middyjs/middy/issues/485 | ||
test('It will stop invoking all the onError handlers if one of them returns a promise that rejects', (endTest) => { | ||
const handler = middy((event, context) => { | ||
throw new Error('something bad happened') | ||
}) | ||
const middleware1 = { | ||
onError: (handler) => { | ||
handler.response = { error: handler.error } | ||
return Promise.reject(handler.error) | ||
} | ||
} | ||
const middleware2 = { | ||
onError: (handler) => { | ||
handler.middleware2_called = true | ||
return Promise.resolve(handler.error) | ||
} | ||
} | ||
handler | ||
.use(middleware1) | ||
.use(middleware2) | ||
handler({}, {}, (err, response) => { | ||
expect(err.message).toBe('something bad happened') | ||
expect(response).not.toBeDefined() | ||
expect(handler.middleware2_called).not.toBeDefined() | ||
endTest() | ||
}) | ||
}) | ||
test('Middlewares can be stopped by calling the callback from the context', (endTest) => { | ||
@@ -711,0 +772,0 @@ const beforeMiddleware = (handler, next) => { |
{ | ||
"name": "@middy/core", | ||
"version": "1.0.0-beta.10", | ||
"version": "1.0.0-beta.11", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)", | ||
@@ -48,3 +48,3 @@ "engines": { | ||
}, | ||
"gitHead": "fdab45ba5ab9477dc2faddd1b812f16f56986289" | ||
"gitHead": "34026eed4bcff4b4124b887474cc1163c6cf099c" | ||
} |
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
38312
955