pingCheck method

  1. @override
Future<HealthIndicatorCheck> pingCheck(
  1. RequestContext context
)
override

Returns a map with the status of the specific component. Throws an exception if the component is critically failing.

Implementation

@override
Future<HealthIndicatorCheck> pingCheck(RequestContext context) async {
  final registeredModuleNames = LoxiaModule.registeredModuleNames;
  if (registeredModuleNames.length > 1) {
    bool allStatusUp = true;
    final Map<String, dynamic> details = {};
    for (final module in registeredModuleNames) {
      try {
        final connectivityResult = await _checkLoxiaConnectivity(context);
        details[module] = {'status': 'up', ...connectivityResult};
      } on StateError catch (e) {
        allStatusUp = false;
        details[module] = {'status': 'down', 'error': e.message};
      } catch (e) {
        allStatusUp = false;
        details[module] = {
          'status': 'down',
          'error': 'Unexpected error during Loxia connectivity check',
          'exception': e.toString(),
        };
      }
    }
    return (
      status: allStatusUp ? HealthStatus.up : HealthStatus.down,
      details: details,
    );
  }
  try {
    final connectivityResult = await _checkLoxiaConnectivity(context);
    return (status: HealthStatus.up, details: connectivityResult);
  } on StateError catch (e) {
    return (status: HealthStatus.down, details: {'error': e.message});
  } catch (e) {
    return (
      status: HealthStatus.down,
      details: {
        'error': 'Unexpected error during Loxia connectivity check',
        'exception': e.toString(),
      },
    );
  }
}