diff --git a/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp b/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp index 11a61093666..a2b80b6ec65 100644 --- a/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp +++ b/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp @@ -398,9 +398,9 @@ Result AndroidBuildApi::ArtifactToFile(const DeviceBuild& build, const std::string& artifact, const std::string& path) { const auto url = CF_EXPECT(GetArtifactDownloadUrl(build, artifact)); - bool is_successful_download = - CF_EXPECT(http_client->DownloadToFile(url, path)).HttpSuccess(); - CF_EXPECT_EQ(is_successful_download, true); + auto response = CF_EXPECT(http_client->DownloadToFile(url, path)); + CF_EXPECTF(response.HttpSuccess(), "Failed to download file: {}", + response.StatusDescription()); return {}; } diff --git a/base/cvd/cuttlefish/host/libs/web/http_client/http_client.h b/base/cvd/cuttlefish/host/libs/web/http_client/http_client.h index 7e59f12e5f0..1a045969e00 100644 --- a/base/cvd/cuttlefish/host/libs/web/http_client/http_client.h +++ b/base/cvd/cuttlefish/host/libs/web/http_client/http_client.h @@ -17,12 +17,12 @@ #include #include -#include #include #include #include #include +#include #include "common/libs/utils/result.h" @@ -32,11 +32,27 @@ struct HttpVoidResponse {}; template struct HttpResponse { - bool HttpInfo() { return http_code >= 100 && http_code <= 199; } - bool HttpSuccess() { return http_code >= 200 && http_code <= 299; } - bool HttpRedirect() { return http_code >= 300 && http_code <= 399; } - bool HttpClientError() { return http_code >= 400 && http_code <= 499; } - bool HttpServerError() { return http_code >= 500 && http_code <= 599; } + bool HttpInfo() const { return http_code >= 100 && http_code <= 199; } + bool HttpSuccess() const { return http_code >= 200 && http_code <= 299; } + bool HttpRedirect() const { return http_code >= 300 && http_code <= 399; } + bool HttpClientError() const { return http_code >= 400 && http_code <= 499; } + bool HttpServerError() const { return http_code >= 500 && http_code <= 599; } + + std::string StatusDescription() const { + switch (http_code) { + case 200: return "OK"; + case 201: return "Created"; + case 204: return "No Content"; + case 400: return "Bad Request"; + case 401: return "Unauthorized"; + case 403: return "Forbidden"; + case 404: return "File Not Found"; + case 500: return "Internal Server Error"; + case 502: return "Bad Gateway"; + case 503: return "Service Unavailable"; + default: return fmt::format("Status Code: {}", http_code); + } + } typename std::conditional, HttpVoidResponse, T>::type data; long http_code;