1+ import { Logger } from '@rocket.chat/logger' ;
12import type { Method } from '@rocket.chat/rest-typings' ;
23import type { AnySchema } from 'ajv' ;
34import express from 'express' ;
@@ -9,6 +10,8 @@ import qs from 'qs'; // Using qs specifically to keep express compatibility
910import type { ResponseSchema , TypedOptions } from './definition' ;
1011import { honoAdapterForExpress } from './middlewares/honoAdapterForExpress' ;
1112
13+ const logger = new Logger ( 'HttpRouter' ) ;
14+
1215type MiddlewareHandlerListAndActionHandler < TOptions extends TypedOptions , TContext = ( c : Context ) => Promise < ResponseSchema < TOptions > > > = [
1316 ...MiddlewareHandler [ ] ,
1417 TContext ,
@@ -199,6 +202,7 @@ export class Router<
199202 if ( options . query ) {
200203 const validatorFn = options . query ;
201204 if ( typeof options . query === 'function' && ! validatorFn ( queryParams ) ) {
205+ logger . warn ( 'Invalid query params' , { error : validatorFn . errors ?. map ( ( error : any ) => error . message ) . join ( '\n ' ) } ) ;
202206 return c . json (
203207 {
204208 success : false ,
@@ -215,6 +219,7 @@ export class Router<
215219 if ( options . body ) {
216220 const validatorFn = options . body ;
217221 if ( typeof options . body === 'function' && ! validatorFn ( ( req as any ) . bodyParams || bodyParams ) ) {
222+ logger . warn ( 'Invalid body params' , { error : validatorFn . errors ?. map ( ( error : any ) => error . message ) . join ( '\n ' ) } ) ;
218223 return c . json (
219224 {
220225 success : false ,
@@ -240,6 +245,7 @@ export class Router<
240245 throw new Error ( `Missing response validator for endpoint ${ req . method } - ${ req . url } with status code ${ statusCode } ` ) ;
241246 }
242247 if ( responseValidatorFn && ! responseValidatorFn ( coerceDatesToStrings ( body ) ) ) {
248+ logger . warn ( 'Invalid response' , { error : responseValidatorFn . errors ?. map ( ( error : any ) => error . message ) . join ( '\n ' ) } ) ;
243249 return c . json (
244250 {
245251 success : false ,
0 commit comments