Updating health controller to throw 503 if unhealthy

This commit is contained in:
Collin Duncan 2024-09-19 12:02:47 +02:00
parent 4fc6748821
commit 6dd515e8eb
No known key found for this signature in database

View file

@ -1,4 +1,9 @@
import { Controller, Get, Inject } from '@nestjs/common'
import {
Controller,
Get,
Inject,
ServiceUnavailableException,
} from '@nestjs/common'
import { EmailProvider } from '../email/provider'
@ -11,6 +16,11 @@ export class HealthController {
@Get()
getHealth() {
return this.emailProvider.isConnected()
const checks = [() => this.emailProvider.isConnected()]
const healthy = checks.every((check) => check())
if (!healthy) {
throw new ServiceUnavailableException()
}
}
}