Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: use FutureOr to allow synchronous interceptors #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/models/interceptor_contract.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:http/http.dart';

///Interceptor interface to create custom Interceptor for http.
Expand Down Expand Up @@ -26,11 +28,11 @@ import 'package:http/http.dart';
///}
///```
abstract class InterceptorContract {
Future<bool> shouldInterceptRequest() async => true;
FutureOr<bool> shouldInterceptRequest() => true;

Future<BaseRequest> interceptRequest({required BaseRequest request});
FutureOr<BaseRequest> interceptRequest({required BaseRequest request});

Future<bool> shouldInterceptResponse() async => true;
FutureOr<bool> shouldInterceptResponse() => true;

Future<BaseResponse> interceptResponse({required BaseResponse response});
FutureOr<BaseResponse> interceptResponse({required BaseResponse response});
}
7 changes: 3 additions & 4 deletions lib/models/retry_policy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ import 'package:http/http.dart';
abstract class RetryPolicy {
/// Defines whether the request should be retried when an Exception occurs
/// while making said request to the server.
Future<bool> shouldAttemptRetryOnException(
Exception reason, BaseRequest request) async =>
FutureOr<bool> shouldAttemptRetryOnException(
Exception reason, BaseRequest request) =>
false;

/// Defines whether the request should be retried after the request has
/// received `response` from the server.
Future<bool> shouldAttemptRetryOnResponse(BaseResponse response) async =>
false;
FutureOr<bool> shouldAttemptRetryOnResponse(BaseResponse response) => false;

/// Number of maximum request attempts that can be retried.
final int maxRetryAttempts = 1;
Expand Down