handleTimeoutError method

Future<bool> handleTimeoutError({
  1. required String relayUrl,
  2. required int attemptNumber,
  3. required Future<bool> retryFn(),
})

Handle an operation timeout error.

Implementation

Future<bool> handleTimeoutError({
  required String relayUrl,
  required int attemptNumber,
  required Future<bool> Function() retryFn,
}) async {
  _recordError(
    relayUrl: relayUrl,
    errorType: ErrorType.timeoutError,
    attemptNumber: attemptNumber,
  );

  logger.log(
    'Timeout on relay $relayUrl (attempt $attemptNumber)',
  );

  if (attemptNumber > _strategy.maxRetries) {
    logger.log('Max retries exceeded for timeout on relay $relayUrl');
    return false;
  }

  final delay = _strategy.getDelayForAttempt(attemptNumber);
  logger.log(
    'Retrying relay $relayUrl after timeout in ${delay.inMilliseconds}ms',
  );

  await Future<void>.delayed(delay);

  try {
    return await retryFn();
  } catch (e) {
    return handleTimeoutError(
      relayUrl: relayUrl,
      attemptNumber: attemptNumber + 1,
      retryFn: retryFn,
    );
  }
}