Skip to content

Commit

Permalink
feat(readme): Add modifyable key to health indicator
Browse files Browse the repository at this point in the history
To stay consistent with @nestjs/terminus use modifyable status key and
improve error status.
  • Loading branch information
BrunnerLivio authored and willsoto committed Mar 20, 2019
1 parent 86975b2 commit 7e1a082
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<HealthIndicatorResult> {
async ping(key: string = "db-primary"): Promise<HealthIndicatorResult> {
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);
}
}
}
Expand Down

0 comments on commit 7e1a082

Please sign in to comment.