Browse Source

chore: better exception handle

test
Amio 6 years ago
parent
commit
1bcfef284d
  1. 8
      libs/live-badge-handlers.js

8
libs/live-badge-handlers.js

@ -10,12 +10,12 @@ module.exports = Object.entries(liveFns).map(([name, fn]) => {
subject = name, subject = name,
status = 'unknown', status = 'unknown',
color = 'grey', color = 'grey',
fail = false failed = false
} = await fetchLiveParams(name, fn, req.params['*']) } = await fetchLiveParams(name, fn, req.params['*'])
req.params = { subject, status, color, style } req.params = { subject, status, color, style }
serveBadge(req, res, { serveBadge(req, res, {
maxAge: fail ? '0' : (Math.random() * 240 + 120).toFixed() maxAge: failed ? '0' : (Math.random() * 240 + 120).toFixed()
}) })
}) })
}) })
@ -27,11 +27,11 @@ async function fetchLiveParams (scope, fn, paramsPath) {
console.time(fetchKey) console.time(fetchKey)
waitings[fetchKey] = fn(...paramsPath.split('/')).catch(e => { waitings[fetchKey] = fn(...paramsPath.split('/')).catch(e => {
console.error(fetchKey, 'LIVE_ERROR', e.message) console.error(fetchKey, 'LIVE_ERROR', e.message)
return { fail: true } return { failed: true }
}).then(result => { }).then(result => {
console.timeEnd(fetchKey) console.timeEnd(fetchKey)
waitings[fetchKey] = undefined waitings[fetchKey] = undefined
return result return result || { failed: true }
}) })
return waitings[fetchKey] return waitings[fetchKey]

Loading…
Cancel
Save