Skip to content

Commit 8998e52

Browse files
committed
move hydro sentry error out of /events, to hydro
1 parent 008faf5 commit 8998e52

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

lib/hydro.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const crypto = require('crypto')
22
const fetch = require('node-fetch')
33
const statsd = require('../lib/statsd')
4+
const FailBot = require('../lib/failbot')
45

56
const hydroStats = statsd.childClient({
67
prefix: 'hydro.'
@@ -82,6 +83,21 @@ module.exports = class Hydro {
8283
hydroStats.increment(`response_code.${res.statusCode}`, 1)
8384
hydroStats.increment('response_code.all', 1)
8485

86+
// Track hydro exceptions in Sentry, but don't track 503s because we can't do anything about service availability
87+
if (!res.ok && res.status !== 503) {
88+
const err = new Error(`Hydro request failed: ${res.statusText}`)
89+
err.status = res.status
90+
err.path = fields.path
91+
92+
FailBot.report(err, {
93+
path: fields.path,
94+
hydroStatus: res.status,
95+
hydroText: res.statusText
96+
})
97+
98+
throw err;
99+
}
100+
85101
return res;
86102
}
87103
}

middleware/events.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const express = require('express')
22
const { omit } = require('lodash')
33
const Ajv = require('ajv')
44
const schema = require('../lib/schema-event')
5-
const FailBot = require('../lib/failbot')
65

76
const OMIT_FIELDS = ['type', 'token']
87

@@ -25,22 +24,7 @@ router.post('/', async function postEvents (req, res, next) {
2524
req.hydro.publish(
2625
req.hydro.schemas[fields.type],
2726
omit(fields, OMIT_FIELDS)
28-
).then(async (hydroRes) => {
29-
// Track hydro exceptions in Sentry, but don't track 503s because we can't do anything about service availability
30-
if (!hydroRes.ok && hydroRes.status !== 503) {
31-
const err = new Error(`Hydro request failed: ${hydroRes.statusText}`)
32-
err.status = hydroRes.status
33-
err.path = fields.path
34-
35-
await FailBot.report(err, {
36-
path: fields.path,
37-
hydroStatus: hydroRes.status,
38-
hydroText: hydroRes.statusText
39-
})
40-
41-
throw err
42-
}
43-
}).catch((e) => {
27+
).catch((e) => {
4428
if (isDev) console.error(e)
4529
})
4630
}

0 commit comments

Comments
 (0)