Skip to content

Commit b6931d0

Browse files
committed
Reverted request body extraction simplification
1 parent 761ee09 commit b6931d0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/event-handler/src/http/middleware/validation.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ export const createValidationMiddleware = <
3636
if (reqSchemas.body) {
3737
const clonedRequest = reqCtx.req.clone();
3838
const contentType = reqCtx.req.headers.get('content-type');
39-
const bodyData = contentType?.includes('application/json')
40-
? await clonedRequest.json()
41-
: await clonedRequest.text();
39+
let bodyData: unknown;
40+
41+
if (contentType?.includes('application/json')) {
42+
try {
43+
bodyData = await clonedRequest.json();
44+
} catch {
45+
// If JSON parsing fails, get as text and let validator handle it
46+
bodyData = await reqCtx.req.clone().text();
47+
}
48+
} else {
49+
bodyData = await clonedRequest.text();
50+
}
4251

4352
const validatedBody = await validateRequest(
4453
reqSchemas.body,

0 commit comments

Comments
 (0)