Skip to content

Retry HTTP requests when they fail due to IO errors #1835

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

Merged
merged 1 commit into from
Mar 20, 2018
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
7 changes: 7 additions & 0 deletions lib/src/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ final httpClient = new ThrottleClient(
new _ThrowingClient(new RetryClient(_pubClient,
retries: 5,
when: (response) => const [502, 503, 504].contains(response.statusCode),
whenError: (error, stackTrace) {
if (error is! IOException) return false;

var chain = new Chain.forTrace(stackTrace);
log.io("HTTP error:\n$error\n\n${chain.terse}");
return true;
},
delay: (retryCount) {
if (retryCount < 3) {
// Retry quickly a couple times in case of a short transient error.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
glob: "^1.0.0"
http: "^0.11.0"
http_multi_server: ">=1.0.0 <3.0.0"
http_retry: "^0.1.0"
http_retry: "^0.1.1"
http_throttle: "^1.0.0"
json_rpc_2: "^2.0.0"
meta: "^1.1.0"
Expand Down