How to use the @godaddy/terminus.HealthCheckError function in @godaddy/terminus

To help you get started, we’ve selected a few @godaddy/terminus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nestjs / terminus / lib / health-indicators / dns / dns.health.ts View on Github external
private generateHttpError(key: string, error: AxiosError) {
    // TODO: Check for `error.isAxiosError`
    // Upgrade axios for that as soon ^0.19.0 is released
    if (error) {
      const response: { [key: string]: any } = {
        message: error.message,
      };
      if (error.response) {
        response.statusCode = error.response.status;
        response.statusText = error.response.statusText;
      }
      throw new HealthCheckError(
        error.message,
        this.getStatus(key, false, response),
      );
    }
  }
github nestjs / terminus / e2e / custom-logger.e2e-spec.ts View on Github external
it('should log an error to the custom logger if an error has been thrown', async () => {
    const mockLogger = (message: string, error: HealthCheckError) => {
      expect(message).toBe('healthcheck failed');
      expect(error.causes).toEqual({ test: 'test' });
    };

    const healthError = new HealthCheckError('test', { test: 'test' });
    const testHealthInidcator = async () => {
      throw healthError;
    };

    const endpoints: TerminusEndpoint[] = [
      {
        url: '/health',
        healthIndicators: [testHealthInidcator],
      },
    ];

    [app, port] = await bootstrapModule({
      useFactory: (): TerminusModuleOptions => ({
        endpoints,
        logger: mockLogger,
      }),
github nestjs / terminus / lib / health-indicators / microservice / grpc.health.ts View on Github external
timeout: 1000,
      healthServiceName: 'Health',
    };

    const settings = { ...defaultOptions, ...options };

    const client = this.createClient(settings);

    let healthService: GRPCHealthService;
    try {
      healthService = client.getService(
        settings.healthServiceName,
      );
    } catch (err) {
      if (err instanceof TypeError) throw err;
      throw new HealthCheckError(
        err.message,
        this.getStatus(key, false, { message: err.message }),
      );
    }

    let response: HealthCheckResponse;

    try {
      response = await promiseTimeout(
        settings.timeout,
        settings.healthServiceCheck(healthService, service),
      );
    } catch (err) {
      if (err instanceof PromiseTimeoutError) {
        throw new TimeoutError(
          settings.timeout,
github danielwii / asuna-node-server / src / modules / providers / mq.health.ts View on Github external
async isHealthy(key: string): Promise {
    const isHealthy = MQProvider.enabled;

    const result = this.getStatus(key, isHealthy, {
      enabled: MQProvider.enabled,
    });

    if (isHealthy) {
      return result;
    }
    throw new HealthCheckError('MQCheck failed', result);
  }
}
github danielwii / asuna-node-server / src / modules / providers / redis.health.ts View on Github external
async isHealthy(key: string): Promise {
    const redisClientObject = RedisProvider.instance.getRedisClient();
    const isHealthy = !redisClientObject.isEnabled || redisClientObject.isHealthy;

    const result = this.getStatus(key, isHealthy, {
      enabled: redisClientObject.isEnabled,
      isHealthy: redisClientObject.isHealthy,
      config: redisClientObject.redisOptions,
    });

    if (isHealthy) {
      return result;
    }
    throw new HealthCheckError('RedisCheck failed', result);
  }
}
github nestjs / terminus / lib / health-indicators / microservice / microservice.health.ts View on Github external
private generateError(key: string, error: Error, timeout: number) {
    if (!error) {
      return;
    }
    if (error instanceof PromiseTimeoutError) {
      throw new TimeoutError(
        timeout,
        this.getStatus(key, false, {
          message: `timeout of ${timeout}ms exceeded`,
        }),
      );
    }
    throw new HealthCheckError(
      error.message,
      this.getStatus(key, false, {
        message: error.message,
      }),
    );
  }
github nestjs / terminus / lib / terminus-bootstrap.service.ts View on Github external
return async () => {
      const { results, errors } = await this.executeHealthIndicators(
        endpoint.healthIndicators,
      );

      const info = (results || [])
        .concat(errors || [])
        .reduce(
          (previous: Object, current: Object) =>
            Object.assign(previous, current),
          {},
        );

      if (errors.length) {
        throw new HealthCheckError('Healthcheck failed', info);
      } else {
        return info;
      }
    };
  }
github xmlking / ngx-starter-kit / apps / api / src / app / project / kubernetes / kubernetes.health.ts View on Github external
async pingCheck(key: string): Promise {
    const badboys = this.dogs.filter(dog => dog.type === 'badboy');
    const isHealthy = badboys.length > 0;
    const result = this.getStatus(key, isHealthy, { badboys: badboys.length });

    if (isHealthy) {
      return result;
    }
    throw new HealthCheckError('Dogcheck failed', result);
  }
}
github nestjs / terminus / lib / terminus-bootstrap.service.spec.ts View on Github external
const downHealthIndicator = jest.fn().mockImplementation(() => {
  throw new HealthCheckError('Down', { down: { status: 'down' } });
});

@godaddy/terminus

[![Join Slack](https://img.shields.io/badge/Join%20us%20on-Slack-e01563.svg)](https://godaddy-oss.slack.com/) [![Build Status](https://github.com/godaddy/terminus/actions/workflows/cicd.yml/badge.svg)](https://github.com/godaddy/terminus/actions/workflows

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Similar packages