Skip to content

Commit

Permalink
Tweak /events exception reporting (github#17776)
Browse files Browse the repository at this point in the history
* Include fields as metadata instead of error inst

* Include hydroText
  • Loading branch information
JasonEtco authored Feb 9, 2021
1 parent 1918d2e commit 4a23a3e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions middleware/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const router = express.Router()

router.post('/', async (req, res, next) => {
const isDev = process.env.NODE_ENV === 'development'
const referrer = req.get('referrer')
const fields = omit(req.body, '_csrf')

if (!ajv.validate(schema, fields)) {
Expand All @@ -34,18 +33,20 @@ router.post('/', async (req, res, next) => {
if (!hydroRes.ok) {
const err = new Error('Hydro request failed')
err.status = hydroRes.status
err.path = fields.path

await FailBot.report(err, {
path: fields.path,
hydroStatus: hydroRes.status,
hydroText: await hydroRes.text()
})

throw err
}

return res.status(201).json(fields)
} catch (err) {
if (isDev) console.error(err)

await FailBot.report(err, {
path: req.path,
referrer
})

return res.status(502).json({})
}
})
Expand Down

0 comments on commit 4a23a3e

Please sign in to comment.