Updating health controller to throw 503 if unhealthy
This commit is contained in:
parent
4fc6748821
commit
6dd515e8eb
1 changed files with 12 additions and 2 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
import { Controller, Get, Inject } from '@nestjs/common'
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Inject,
|
||||||
|
ServiceUnavailableException,
|
||||||
|
} from '@nestjs/common'
|
||||||
|
|
||||||
import { EmailProvider } from '../email/provider'
|
import { EmailProvider } from '../email/provider'
|
||||||
|
|
||||||
|
|
@ -11,6 +16,11 @@ export class HealthController {
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getHealth() {
|
getHealth() {
|
||||||
return this.emailProvider.isConnected()
|
const checks = [() => this.emailProvider.isConnected()]
|
||||||
|
|
||||||
|
const healthy = checks.every((check) => check())
|
||||||
|
if (!healthy) {
|
||||||
|
throw new ServiceUnavailableException()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue