RetryPolicy class abstract

Defines the behavior for retrying requests.

Example:

class ExpiredTokenRetryPolicy extends RetryPolicy {
  @override
  int get maxRetryAttempts => 2;

  @override
  bool shouldAttemptRetryOnException(Exception reason) {
    log(reason.toString());

    return false;
  }

  @override
  Future<bool> shouldAttemptRetryOnResponse(BaseResponse response) async {
    if (response.statusCode == 401) {
      log("Retrying request...");
      final cache = await SharedPreferences.getInstance();

      cache.setString(kOWApiToken, OPEN_WEATHER_API_KEY);

      return true;
    }

    return false;
  }
}

Constructors

RetryPolicy()

Properties

hashCode int
The hash code for this object.
no setterinherited
maxRetryAttempts int
Number of maximum request attempts that can be retried.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delayRetryAttemptOnException({required int retryAttempt}) Duration
delayRetryAttemptOnResponse({required int retryAttempt}) Duration
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldAttemptRetryOnException(Exception reason, BaseRequest request) FutureOr<bool>
Defines whether the request should be retried when an Exception occurs while making said request to the server.
shouldAttemptRetryOnResponse(BaseResponse response) FutureOr<bool>
Defines whether the request should be retried after the request has received response from the server.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited