probeReachability method

  1. @override
Future<EcrReachability> probeReachability(
  1. EcrRequest request
)
override

Asks whether the terminal is there, with the underlying error when it is not. Never throws for an unreachable link — see EcrReachability.error.

Implementation

@override
Future<EcrReachability> probeReachability(EcrRequest request) async {
  // A probe cannot leave anything half-done, so it needs none of the
  // one-shot machinery — and a host that breaks answers "not reachable",
  // which is true of a host that cannot be asked.
  try {
    final Object? payload = await channel.invokeMethod<Object?>(
      EcrMethods.probeReachability,
      request.toArguments(),
    );
    return EcrCodec.reachability(payload);
  } on PlatformException catch (error) {
    if (error.code == EcrErrorCodes.invalidArgument) {
      throw EcrArgumentError(error.message ?? 'Invalid arguments');
    }
    return EcrReachability(
      reachable: false,
      host: request.host,
      port: request.config.port,
      error: error.message ?? error.code,
    );
  } on MissingPluginException {
    return EcrReachability(
      reachable: false,
      host: request.host,
      port: request.config.port,
      error: 'The Amwal ECR plugin is not registered on this platform',
    );
  }
}