generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 180
Closed
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Description
Expected Behavior
The Response in reqCtx.res should also get mutated when a middleware returns early when there are multiple middlewares. The middleware that would do the post processing should be able to access the response returned by the earlier middleware
Current Behavior
The Response in reqCtx.res doesn't get mutated and the post processing middleware can't access the response
Code snippet
This test fails currently as the response is not being mutated
it('allows post processing middleware to access the response returned early by a pre processing middleware', async () => {
// Prepare
const app = new Router();
let message = "";
app.get('/test', [
async ({ reqCtx, next }) => {
await next();
const clonedRes = reqCtx.res.clone();
message = (await clonedRes.json()).message;
},
() => {
return Promise.resolve({ message: 'Middleware applied' })
}
], () => {
return { message: 'Handler applied' }
});
// Act
await app.resolve(
createTestEvent('/test', 'GET'),
context
);
// Assess
expect(message).toEqual('Middleware applied');
})Steps to Reproduce
- Run the above unit test in the project
- The message is empty and hasn't been mutated
Possible Solution
Move the Response mutation logic in Router.ts to the composeMiddleware helper function
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Type
Projects
Status
Shipped