From 7e1a0824629b025a504244518ef60b1ed3da52f3 Mon Sep 17 00:00:00 2001 From: Livio Brunner Date: Wed, 20 Mar 2019 09:37:37 +0100 Subject: [PATCH] feat(readme): Add modifyable key to health indicator To stay consistent with @nestjs/terminus use modifyable status key and improve error status. --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ee7fc54a..8f447559 100644 --- a/README.md +++ b/README.md @@ -110,24 +110,20 @@ export class DatabaseModule {} ```ts import { HealthCheckError } from "@godaddy/terminus"; import { Inject, Injectable } from "@nestjs/common"; -import { HealthIndicatorResult } from "@nestjs/terminus"; +import { HealthIndicatorResult, HealthIndicator } from "@nestjs/terminus"; import { Connection, KNEX_CONNECTION } from "@willsoto/nestjs-objection"; @Injectable() -export class PrimaryDatabaseHealthIndicator { +export class PrimaryDatabaseHealthIndicator extends HealthIndicator { constructor(@Inject(KNEX_CONNECTION) public connection: Connection) {} - async ping(): Promise { + async ping(key: string = "db-primary"): Promise { try { await this.connection.raw("SELECT 1"); - - return { - "db-primary": { - status: "up" - } - }; + return super.getStatus(key, true); } catch (error) { - throw new HealthCheckError("Unable to connect to database", error); + const status = super.getStatus(key, false, { message: error.message }); + throw new HealthCheckError("Unable to connect to database", status); } } }