Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const timeout = options.timeout || 1000;
if (!connection) {
throw new ConnectionNotFoundError(
this.getStatus(key, isHealthy, {
message: 'Connection provider not found in application context',
}),
);
}
try {
await this.pingDb(connection, timeout);
isHealthy = true;
} catch (err) {
if (err instanceof PromiseTimeoutError) {
throw new TimeoutError(
timeout,
this.getStatus(key, isHealthy, {
message: `timeout of ${timeout}ms exceeded`,
}),
);
}
}
if (isHealthy) {
return this.getStatus(key, isHealthy);
} else {
throw new HealthCheckError(
`${key} is not available`,
this.getStatus(key, isHealthy),
);
}