Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
log body in error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ildella committed Sep 23, 2023
1 parent 236d34e commit 742178e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions http/http-error-handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// eslint-disable-next-line complexity
const errorHandler = ({verbose = true} = {}) => (error, {
log,
id, ip, hostname, originalUrl, url,
id, ip, hostname, originalUrl, url, body,
},
reply) => {
log.debug({
id, ip, hostname, originalUrl, url,
id, ip, hostname, originalUrl, url, body,
})
const code = error.status || error.statusCode || 500
const toPrint = verbose === true ? error : {message: error.message}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moar-js",
"version": "1.1.0",
"version": "1.1.1",
"description": "Simple JavaScript files I use across projects",
"author": {
"name": "Daniele Dellafiore"
Expand Down
33 changes: 32 additions & 1 deletion tests/http/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const {defaultHttpJsonClient} = require('../../axios')
const {__} = require('../../fusto/')

// eslint-disable-next-line max-lines-per-function
module.exports = app => {
app.get('/health', request => {
const ip = request.socket.remoteAddress
Expand Down Expand Up @@ -32,4 +34,33 @@ module.exports = app => {
const {get} = defaultHttpJsonClient('http://duckduckgo.com', {timeout: 1})
await get('/')
})
return app}

app.get('/async-pipe-booom', async (request, reply) => {
await __([1])
// eslint-disable-next-line require-await
.map(async () => {
// eslint-disable-next-line fp/no-throw
throw new Error('big booom in the async pipeline')
})
.resolve()
.errors((error, push) => push(error))
.toPromise()
reply.code(200).send({})
})

app.get('/hijack-async-pipe-booom', async (request, reply) => {
reply.hijack()
await __([1])
// eslint-disable-next-line require-await
.map(async () => {
// eslint-disable-next-line fp/no-throw
throw new Error('big booom in the async pipeline')
})
.resolve()
.errors((error, push) => push(error))
.toPromise(() => reply.code(200).send({}))
return 'This will be ignored.'
})

return app
}

0 comments on commit 742178e

Please sign in to comment.