瀏覽代碼

Retry on failure; dont try to write to dead client

Chris Mullins 8 年之前
父節點
當前提交
9996c69f2a
共有 2 個文件被更改,包括 7 次插入1 次删除
  1. 2 0
      lib/GithubClient/GithubClient.cpp
  2. 5 1
      lib/WebServer/MiLightHttpServer.cpp

+ 2 - 0
lib/GithubClient/GithubClient.cpp

@@ -4,10 +4,12 @@
 Stream& GithubClient::stream(const String& path) {
   if (!client.connect(domain.c_str(), 443)) {
     Serial.println(F("Failed to connect to github over HTTPS."));
+    return client;
   }
   
   if (!client.verify(sslFingerprint.c_str(), domain.c_str())) {
     Serial.println(F("Failed to verify github certificate"));
+    return client;
   }
   
   client.printf(

+ 5 - 1
lib/WebServer/MiLightHttpServer.cpp

@@ -70,7 +70,11 @@ void MiLightHttpServer::handleGetLatestRelease() {
   // headers in the response from GitHub, which seems like more trouble than
   // it's worth.
   const String& fsPath = "/_cv.json";
-  client.download(path, fsPath);
+  size_t tries = 0;
+  
+  while (tries++ < MAX_DOWNLOAD_ATTEMPTS && !client.download(path, fsPath)) {
+    Serial.println(F("Failed download attempt."));
+  }
   
   File file = SPIFFS.open(fsPath, "r");
   server.streamFile(file, "application/json");