Merge pull request #1230 from balena-io/fix-unhandled-health-rejection

Don't throw an error when getting an unhealthy state
This commit is contained in:
CameronDiver 2020-03-30 11:08:07 +01:00 committed by GitHub
commit 20e339317e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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'));