Skip to content

Commit 7ad83ad

Browse files
committed
Pass BaseResponse to when()
This makes it clear that callers shouldn't try to read the response body in the callback.
1 parent 694e34f commit 7ad83ad

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/http_retry.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class RetryClient extends BaseClient {
1717
final int _retries;
1818

1919
/// The callback that determines whether a request should be retried.
20-
final bool Function(StreamedResponse) _when;
20+
final bool Function(BaseResponse) _when;
2121

2222
/// The callback that determines how long to wait before retrying a request.
2323
final Duration Function(int) _delay;
@@ -37,7 +37,7 @@ class RetryClient extends BaseClient {
3737
/// given (zero-based) retry.
3838
RetryClient(this._inner,
3939
{int retries,
40-
bool when(StreamedResponse response),
40+
bool when(BaseResponse response),
4141
Duration delay(int retryCount)})
4242
: _retries = retries ?? 3,
4343
_when = when ?? ((response) => response.statusCode == 503),
@@ -54,13 +54,15 @@ class RetryClient extends BaseClient {
5454
/// in order. It will wait for `delays[0]` after the initial request,
5555
/// `delays[1]` after the first retry, and so on.
5656
RetryClient.withDelays(Client inner, Iterable<Duration> delays,
57-
{bool when(StreamedResponse response)})
57+
{bool when(BaseResponse response)})
5858
: this._withDelays(inner, delays.toList(), when: when);
5959

6060
RetryClient._withDelays(Client inner, List<Duration> delays,
61-
{bool when(StreamedResponse response)})
61+
{bool when(BaseResponse response)})
6262
: this(inner,
63-
retries: delays.length, delay: (retryCount) => delays[retryCount]);
63+
retries: delays.length,
64+
delay: (retryCount) => delays[retryCount],
65+
when: when);
6466

6567
Future<StreamedResponse> send(BaseRequest request) async {
6668
var splitter = new StreamSplitter(request.finalize());

0 commit comments

Comments
 (0)