Don't throw an error when getting an unhealthy state

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-03-30 10:07:50 +01:00
parent 8fdd5a4e65
commit 6b827a3f57

View File

@ -103,11 +103,17 @@ export class SupervisorAPI {
this.api.use(expressLogger);
this.api.get('/v1/healthy', async (_req, res) => {
const healths = await Promise.all(this.healthchecks.map(fn => fn()));
if (!_.every(healths)) {
throw new Error('Unhealthy');
try {
const healths = await Promise.all(this.healthchecks.map(fn => fn()));
if (!_.every(healths)) {
log.error('Healthcheck failed');
return res.status(500).send('Unhealthy');
}
return res.sendStatus(200);
} catch (_e) {
log.error('Healthcheck failed');
return res.status(500).send('Unhealthy');
}
return res.sendStatus(200);
});
this.api.get('/ping', (_req, res) => res.send('OK'));