]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix(http-storage): Report connection timeout properly
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 7 Nov 2022 08:16:15 +0000 (09:16 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 7 Nov 2022 18:27:36 +0000 (19:27 +0100)
src/storage/remote/HttpStorage.cpp

index 284e1d72bf8641130e76814f163693e3e8d112d7..26c8918a2f5b0d5a5a0d6ccb635f496d1a4af328 100644 (file)
@@ -94,6 +94,14 @@ get_url(const Url& url)
   return get_partial_url(url).str();
 }
 
+RemoteStorage::Backend::Failure
+failure_from_httplib_error(httplib::Error error)
+{
+  return error == httplib::Error::ConnectionTimeout
+           ? RemoteStorage::Backend::Failure::timeout
+           : RemoteStorage::Backend::Failure::error;
+}
+
 HttpStorageBackend::HttpStorageBackend(const Params& params)
   : m_url_path(get_url_path(params.url)),
     m_http_client(get_url(params.url))
@@ -155,7 +163,7 @@ HttpStorageBackend::get(const Digest& key)
         url_path,
         to_string(result.error()),
         static_cast<int>(result.error()));
-    return nonstd::make_unexpected(Failure::error);
+    return nonstd::make_unexpected(failure_from_httplib_error(result.error()));
   }
 
   if (result->status < 200 || result->status >= 300) {
@@ -181,7 +189,8 @@ HttpStorageBackend::put(const Digest& key,
           url_path,
           to_string(result.error()),
           static_cast<int>(result.error()));
-      return nonstd::make_unexpected(Failure::error);
+      return nonstd::make_unexpected(
+        failure_from_httplib_error(result.error()));
     }
 
     if (result->status >= 200 && result->status < 300) {
@@ -204,14 +213,14 @@ HttpStorageBackend::put(const Digest& key,
         url_path,
         to_string(result.error()),
         static_cast<int>(result.error()));
-    return nonstd::make_unexpected(Failure::error);
+    return nonstd::make_unexpected(failure_from_httplib_error(result.error()));
   }
 
   if (result->status < 200 || result->status >= 300) {
     LOG("Failed to put {} to http storage: status code: {}",
         url_path,
         result->status);
-    return nonstd::make_unexpected(Failure::error);
+    return nonstd::make_unexpected(failure_from_httplib_error(result.error()));
   }
 
   return true;
@@ -228,14 +237,14 @@ HttpStorageBackend::remove(const Digest& key)
         url_path,
         to_string(result.error()),
         static_cast<int>(result.error()));
-    return nonstd::make_unexpected(Failure::error);
+    return nonstd::make_unexpected(failure_from_httplib_error(result.error()));
   }
 
   if (result->status < 200 || result->status >= 300) {
     LOG("Failed to delete {} from http storage: status code: {}",
         url_path,
         result->status);
-    return nonstd::make_unexpected(Failure::error);
+    return nonstd::make_unexpected(failure_from_httplib_error(result.error()));
   }
 
   return true;