File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
packages/event-handler/src/http/middleware Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments