Skip to content

Commit

Permalink
feat: added responseTime argument to the custom errorMessage callback (
Browse files Browse the repository at this point in the history
  • Loading branch information
jorra-singh authored May 6, 2024
1 parent 1613425 commit c3d32dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function pinoLogger (opts, stream) {
[errKey]: error,
[responseTimeKey]: responseTime
}),
errorMessage(req, res, error)
errorMessage(req, res, error, responseTime)
)

return
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,26 @@ test('pass responseTime argument to the custom successMessage callback', functio
})
})

test('pass responseTime argument to the custom errorMessage callback', function (t) {
const dest = split(JSON.parse)
const customErrorMessage = 'Response time is:'
const logger = pinoHttp({
customErrorMessage: function (req, res, err, responseTime) {
return `${customErrorMessage} ${responseTime} ${req.method}`
}
}, dest)

setup(t, logger, function (err, server) {
t.error(err)
doGet(server, ERROR_URL)
})

dest.on('data', function (line) {
t.match(line.msg, /Response time is: \d+ GET/)
t.end()
})
})

test('uses the custom successObject callback if passed in as an option', function (t) {
const dest = split(JSON.parse)
const logger = pinoHttp({
Expand Down

0 comments on commit c3d32dd

Please sign in to comment.