From ee062758e74513fa7b058b6c680c5df592e9ba0f Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Wed, 23 Nov 2022 09:17:03 +0200 Subject: [PATCH] fix: HealthCheckError in sync HealthIndicatorFunction Fixes #2083 --- .../health-check-executor.service.spec.ts | 28 +++++++++++++++++++ .../health-check-executor.service.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/health-check/health-check-executor.service.spec.ts b/lib/health-check/health-check-executor.service.spec.ts index 6c892bfef..328b090a9 100644 --- a/lib/health-check/health-check-executor.service.spec.ts +++ b/lib/health-check/health-check-executor.service.spec.ts @@ -20,6 +20,14 @@ const unhealthyCheck = async (): Promise => { }); }; +const unhealthyCheckSync = () => { + throw new HealthCheckError('error', { + unhealthy: { + status: 'down', + }, + }); +}; + describe('HealthCheckExecutorService', () => { let healthCheckExecutor: HealthCheckExecutor; @@ -70,6 +78,26 @@ describe('HealthCheckExecutorService', () => { }); }); + it('should return a result object with errors with sync indicator function', async () => { + const result = await healthCheckExecutor.execute([ + () => unhealthyCheckSync(), + ]); + expect(result).toEqual({ + status: 'error', + info: {}, + error: { + unhealthy: { + status: 'down', + }, + }, + details: { + unhealthy: { + status: 'down', + }, + }, + }); + }); + it('should return a result object without errors and with errors', async () => { const result = await healthCheckExecutor.execute([ () => unhealthyCheck(), diff --git a/lib/health-check/health-check-executor.service.ts b/lib/health-check/health-check-executor.service.ts index be4d65e10..dee3eb53b 100644 --- a/lib/health-check/health-check-executor.service.ts +++ b/lib/health-check/health-check-executor.service.ts @@ -60,7 +60,7 @@ export class HealthCheckExecutor implements BeforeApplicationShutdown { const results: HealthIndicatorResult[] = []; const errors: HealthIndicatorResult[] = []; - const result = await Promise.allSettled(healthIndicators.map((h) => h())); + const result = await Promise.allSettled(healthIndicators.map(async (h) => h())); result.forEach((res) => { if (res.status === 'fulfilled') {