Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async pingCheck(
key: string,
options: MongoPingCheckSettings = {},
): Promise {
let isHealthy = false;
this.checkDependantPackages();
const connection: MongoClient = options.connection || this.getContextConnection();
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`,
}),