From 775a42989b4edc807525dbfec1350e05811efb24 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 20 Mar 2018 13:24:05 -0700 Subject: [PATCH] Retry HTTP requests when they fail due to IO errors Closes #1826 --- lib/src/http.dart | 7 +++++++ pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/http.dart b/lib/src/http.dart index 9f1101270..6ddf80861 100644 --- a/lib/src/http.dart +++ b/lib/src/http.dart @@ -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. diff --git a/pubspec.yaml b/pubspec.yaml index 9c6099574..39781010b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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"