Skip to content

Commit 40a45d8

Browse files
committed
refactor(http-router): enhance logging for validation errors in Router class
1 parent 3903260 commit 40a45d8

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

packages/http-router/src/Router.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ export class Router<
202202
if (options.query) {
203203
const validatorFn = options.query;
204204
if (typeof options.query === 'function' && !validatorFn(queryParams)) {
205-
logger.warn('Invalid query params', { error: validatorFn.errors?.map((error: any) => error.message).join('\n ') });
205+
logger.warn({
206+
msg: 'Query parameters validation failed - route spec does not match request payload',
207+
method: req.method,
208+
path: req.url,
209+
error: validatorFn.errors?.map((error: any) => error.message).join('\n '),
210+
});
206211
return c.json(
207212
{
208213
success: false,
@@ -219,7 +224,12 @@ export class Router<
219224
if (options.body) {
220225
const validatorFn = options.body;
221226
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 ') });
227+
logger.warn({
228+
msg: 'Request body validation failed - route spec does not match request payload',
229+
method: req.method,
230+
path: req.url,
231+
error: validatorFn.errors?.map((error: any) => error.message).join('\n '),
232+
});
223233
return c.json(
224234
{
225235
success: false,
@@ -245,7 +255,12 @@ export class Router<
245255
throw new Error(`Missing response validator for endpoint ${req.method} - ${req.url} with status code ${statusCode}`);
246256
}
247257
if (responseValidatorFn && !responseValidatorFn(coerceDatesToStrings(body))) {
248-
logger.warn('Invalid response', { error: responseValidatorFn.errors?.map((error: any) => error.message).join('\n ') });
258+
logger.warn({
259+
msg: 'Response validation failed - response does not match route spec',
260+
method: req.method,
261+
path: req.url,
262+
error: responseValidatorFn.errors?.map((error: any) => error.message).join('\n '),
263+
});
249264
return c.json(
250265
{
251266
success: false,

0 commit comments

Comments
 (0)