Expected Behavior
Returning { statusCode: 204, body: '' } from an HTTP route should produce a 204 response with no body. The same should hold for status 205 and 304.
Current Behavior
The router returns 500 instead. handlerResultToWebResponse passes the empty string to the Web Response constructor, which rejects a non-null body for these statuses. The router catches that error and returns an internal-server-error response.
Confirmed on current main at 3919a3ce3af3ff9fc10d8f6332260cef063822ec through Router.resolve(): all nine combinations of statuses 204/205/304 and REST API v1/HTTP API v2/ALB return 500.
The nine corresponding controls with body omitted pass, as do three controls returning { statusCode: 200, body: '' }. The existing routing test file, with these regressions added, reports 9 failed and 212 passed.
Code snippet
import { Router } from '@aws-lambda-powertools/event-handler/http';
import type { Context } from 'aws-lambda';
const app = new Router();
app.get('/empty', () => ({
statusCode: 204,
body: '',
}));
export const handler = async (event: unknown, context: Context) =>
app.resolve(event, context);
Steps to Reproduce
- Register the route above.
- Invoke it with a REST API v1, HTTP API v2, or ALB
GET /empty event.
- Observe status 500 instead of 204.
- Repeat with status 205 or 304; both also return 500.
- Remove
body: ''; the requested status is returned correctly.
Possible Solution
Normalize an empty proxy-result body to null before constructing a Web Response for statuses that prohibit a body. Add regression coverage through Router.resolve() for 204, 205, and 304 across all three integrations.
Workaround: omit the body property.
Powertools for AWS Lambda (TypeScript) version
2.35.0 in the source checkout at 3919a3ce3af3ff9fc10d8f6332260cef063822ec.
AWS Lambda function runtime
24.x — reproduced locally on Node.js v24.19.0; no Lambda deployment was used.
Packaging format used
npm
Execution logs
The regression assertions fail with:
AssertionError: expected 500 to be 204
AssertionError: expected 500 to be 205
AssertionError: expected 500 to be 304
Tests: 9 failed | 212 passed (221)
Expected Behavior
Returning
{ statusCode: 204, body: '' }from an HTTP route should produce a 204 response with no body. The same should hold for status 205 and 304.Current Behavior
The router returns 500 instead.
handlerResultToWebResponsepasses the empty string to the WebResponseconstructor, which rejects a non-null body for these statuses. The router catches that error and returns an internal-server-error response.Confirmed on current
mainat3919a3ce3af3ff9fc10d8f6332260cef063822ecthroughRouter.resolve(): all nine combinations of statuses 204/205/304 and REST API v1/HTTP API v2/ALB return 500.The nine corresponding controls with
bodyomitted pass, as do three controls returning{ statusCode: 200, body: '' }. The existing routing test file, with these regressions added, reports 9 failed and 212 passed.Code snippet
Steps to Reproduce
GET /emptyevent.body: ''; the requested status is returned correctly.Possible Solution
Normalize an empty proxy-result body to
nullbefore constructing a WebResponsefor statuses that prohibit a body. Add regression coverage throughRouter.resolve()for 204, 205, and 304 across all three integrations.Workaround: omit the
bodyproperty.Powertools for AWS Lambda (TypeScript) version
2.35.0 in the source checkout at
3919a3ce3af3ff9fc10d8f6332260cef063822ec.AWS Lambda function runtime
24.x — reproduced locally on Node.js v24.19.0; no Lambda deployment was used.
Packaging format used
npm
Execution logs
The regression assertions fail with: