manageLinkException method

void manageLinkException(
  1. QueryResult<Object?> result
)

Handles exceptions from a QueryResult.

This method checks the exception in the QueryResult and throws an appropriate exception based on the type of error:

Implementation

void manageLinkException(QueryResult result) {
  final exception = result.exception?.linkException;
  if (exception == null) return;

  if (exception is UnknownException) {
    if (exception.originalException is TimeoutException) {
      throw TimeoutException(exception.message);
    }
  }

  if (exception is HttpLinkParserException) {
    if (exception.response.statusCode == 429) {
      throw const ArchethicTooManyRequestsException();
    }

    if (exception.response.statusCode == 503) {
      throw const ArchethicServiceUnavailableException();
    }
  }

  throw ArchethicConnectionException(exception.toString());
}