From 48c5f06ac02897e304ecb9474d0da3dec5cc84d5 Mon Sep 17 00:00:00 2001 From: Vikas Rathod Date: Wed, 30 Jul 2025 00:51:59 +0530 Subject: [PATCH 1/4] fix(types): add responseTime to customErrorMessage callback --- index.d.ts | 2 +- index.test-d.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index c7c482d..984061a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -31,7 +31,7 @@ export interface Options pino.LevelWithSilent | CustomLevels) | undefined; customReceivedMessage?: ((req: IM, res: SR) => string) | undefined; customSuccessMessage?: ((req: IM, res: SR, responseTime: number) => string) | undefined; - customErrorMessage?: ((req: IM, res: SR, error: Error) => string) | undefined; + customErrorMessage?: ((req: IM, res: SR, error: Error, responseTime: number) => string) | undefined; customReceivedObject?: ((req: IM, res: SR, val?: any) => any) | undefined; customSuccessObject?: ((req: IM, res: SR, val: any) => any) | undefined; customErrorObject?: ((req: IM, res: SR, error: Error, val: any) => any) | undefined; diff --git a/index.test-d.ts b/index.test-d.ts index 8b10fb1..ce14f4a 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -48,6 +48,9 @@ pinoHttp({ customSuccessMessage: (req: CustomRequ // #customErrorMessage pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error) => `Error - ${error}` }); pinoHttp({ customErrorMessage: (req: CustomRequest, res: CustomResponse, error: Error) => `Error - ${error}` }); +pinoHttp({ + customErrorMessage: (req, res, error, responseTime) => `Error - ${error.message} after ${responseTime}ms` +}); // #customAttributeKeys pinoHttp({ customAttributeKeys: { req: 'req' } }); @@ -233,3 +236,6 @@ pinoHttp({ logger: customLogger, customLogLevel: () => 'bark' }) +pinoHttp({ + customErrorMessage: (req, res, error, responseTime) => `Error - ${error.message} after ${responseTime}ms` +}) From f88266849519cbdabeda5b757b49efde9143eb44 Mon Sep 17 00:00:00 2001 From: Vikas Rathod Date: Wed, 30 Jul 2025 01:11:10 +0530 Subject: [PATCH 2/4] refactor(types): remove duplicate customErrorMessage implementation --- index.test-d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index ce14f4a..9b5e2ec 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -236,6 +236,3 @@ pinoHttp({ logger: customLogger, customLogLevel: () => 'bark' }) -pinoHttp({ - customErrorMessage: (req, res, error, responseTime) => `Error - ${error.message} after ${responseTime}ms` -}) From f531bcf766c3ec70783b8bf0015d19dd5eb309ca Mon Sep 17 00:00:00 2001 From: Vikas Rathod Date: Wed, 30 Jul 2025 01:23:49 +0530 Subject: [PATCH 3/4] fix(types): add type annotations to customErrorMessage parameters --- index.test-d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index 9b5e2ec..671d901 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -49,7 +49,7 @@ pinoHttp({ customSuccessMessage: (req: CustomRequ pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error) => `Error - ${error}` }); pinoHttp({ customErrorMessage: (req: CustomRequest, res: CustomResponse, error: Error) => `Error - ${error}` }); pinoHttp({ - customErrorMessage: (req, res, error, responseTime) => `Error - ${error.message} after ${responseTime}ms` + customErrorMessage: (req:IncomingMessage, res:ServerResponse, error:Error, responseTime:number) => `Error - ${error.message} after ${responseTime}ms` }); // #customAttributeKeys @@ -153,7 +153,7 @@ const options: Options = { return `Received HTTP ${req.httpVersion} ${req.method}`; }), customSuccessMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse) => 'successMessage'), - customErrorMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error) => 'errorMessage'), + customErrorMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error, responseTime: number) => 'errorMessage'), customAttributeKeys: canBeUndefined(customAttributeKeys), wrapSerializers: canBeUndefined(rtnBool()), customProps: canBeUndefined((req: IncomingMessage, res: ServerResponse) => ({} as object)), From 67df38e401c950b5296f17f08f0cf2c2dc286383 Mon Sep 17 00:00:00 2001 From: Vikas Rathod Date: Thu, 31 Jul 2025 00:07:37 +0530 Subject: [PATCH 4/4] fix(types): update customErrorMessage tests to use responseTime and clean up redundancy --- index.test-d.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index 671d901..da8c7a3 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -46,11 +46,9 @@ pinoHttp({ customSuccessMessage: (req: IncomingMessage, res: ServerResponse) => pinoHttp({ customSuccessMessage: (req: CustomRequest, res: CustomResponse) => 'Success' }); // #customErrorMessage -pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error) => `Error - ${error}` }); -pinoHttp({ customErrorMessage: (req: CustomRequest, res: CustomResponse, error: Error) => `Error - ${error}` }); -pinoHttp({ - customErrorMessage: (req:IncomingMessage, res:ServerResponse, error:Error, responseTime:number) => `Error - ${error.message} after ${responseTime}ms` -}); +pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error, responseTime:number) => `Error - ${error.message} after ${responseTime}ms` }); +pinoHttp({ customErrorMessage: (req: CustomRequest, res: CustomResponse, error: Error, responseTime:number) => `Error - ${error.message} after ${responseTime}ms` }); + // #customAttributeKeys pinoHttp({ customAttributeKeys: { req: 'req' } });