Skip to content

Commit b57b58f

Browse files
committed
Add more comments
1 parent 72e47c9 commit b57b58f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/src/http.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class PubHttpException implements Exception {
195195
PubHttpException(this.message, {this.isIntermittent = false});
196196
}
197197

198-
/// Exception thrown when an HTTP response is not OK.
198+
/// Exception thrown when an HTTP response is not Ok.
199199
class PubHttpResponseException extends PubHttpException {
200200
final http.Response response;
201201

@@ -216,6 +216,14 @@ class PubHttpResponseException extends PubHttpException {
216216
/// Program-wide limiter for concurrent network requests.
217217
final _httpPool = Pool(16);
218218

219+
/// Runs the provided function [fn] and returns the response.
220+
///
221+
/// If there is an HTTP-related exception, an intermittent HTTP error response,
222+
/// or an async timeout, [fn] is run repeatedly until there is a successful
223+
/// response or at most seven total attempts have been made. If all attempts
224+
/// fail, the final exception is re-thrown.
225+
///
226+
/// Each attempt is run within a [Pool] configured with 16 maximum resources.
219227
Future<T> retryForHttp<T>(String operation, FutureOr<T> Function() fn) async {
220228
return await retry(
221229
() async => await _httpPool.withResource(() async => await fn()),
@@ -235,6 +243,13 @@ Future<T> retryForHttp<T>(String operation, FutureOr<T> Function() fn) async {
235243
}
236244

237245
extension Throwing on http.BaseResponse {
246+
/// Throws [PubHttpResponseException], calls [fail], or does nothing depending
247+
/// on the status code.
248+
///
249+
/// If the code is in the 200 range, nothing is done. If the code is 408, 429,
250+
/// or in the 500 range, [PubHttpResponseException] is thrown with
251+
/// "isIntermittent" set to `true`. Otherwise, [PubHttpResponseException] is
252+
/// thrown with "isIntermittent" set to `false`.
238253
void throwIfNotOk() {
239254
if (statusCode >= 200 && statusCode <= 299) {
240255
return;

0 commit comments

Comments
 (0)