Skip to content

Commit c2caafc

Browse files
committed
add some logs to utils/web, add specific download error for code -1
1 parent 7971cd7 commit c2caafc

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

loader/include/Geode/utils/web.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Task.hpp"
77
#include <chrono>
88
#include <optional>
9+
#include <string_view>
910

1011
namespace geode::utils::web {
1112
GEODE_DLL void openLinkInBrowser(std::string const& url);
@@ -230,7 +231,7 @@ namespace geode::utils::web {
230231

231232
/**
232233
* Sets the Certificate Authority (CA) bundle content.
233-
* Defaults to not sending a CA bundle.
234+
* Defaults to sending the Geode CA bundle, found here: https://github.com/geode-sdk/net_libs/blob/main/ca_bundle.h
234235
*
235236
* @param content
236237
* @return WebRequest&
@@ -248,7 +249,7 @@ namespace geode::utils::web {
248249

249250
/**
250251
* Sets the request's HTTP version.
251-
* The default is HttpVersion::VERSION_2TLS.
252+
* The default is `HttpVersion::DEFAULT`.
252253
*
253254
* @param httpVersion
254255
* @return WebRequest&

loader/src/server/DownloadManager.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "Geode/loader/Mod.hpp"
33
#include <Geode/loader/Dirs.hpp>
44
#include <Geode/utils/map.hpp>
5+
#include <fmt/format.h>
56
#include <optional>
67
#include <hash/hash.hpp>
78
#include <loader/ModImpl.hpp>
@@ -156,9 +157,23 @@ class ModDownload::Impl final {
156157
else {
157158
auto resp = event->getValue();
158159

159-
m_status = DownloadStatusError {
160-
.details = fmt::format("Server returned error {}", resp->code()),
161-
};
160+
if (resp->code() == -1) {
161+
m_status = DownloadStatusError {
162+
.details = fmt::format(
163+
"Failed to make request to download endpoint. Error: {}",
164+
resp->string().unwrapOr("No message")
165+
)
166+
};
167+
} else {
168+
m_status = DownloadStatusError {
169+
.details = fmt::format(
170+
"Server returned error {} with message: {}",
171+
resp->code(),
172+
resp->string().unwrapOr("No message")
173+
)
174+
};
175+
}
176+
162177
log::error("Failed to download {}, server returned error {}", m_id, resp->code());
163178
log::error("{}", resp->string().unwrapOr("No response"));
164179

loader/src/utils/web.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <Geode/loader/Log.hpp>
12
#include <Geode/Result.hpp>
23
#include <Geode/utils/general.hpp>
34
#include <filesystem>
@@ -252,7 +253,8 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
252253
// Init Curl
253254
auto curl = curl_easy_init();
254255
if (!curl) {
255-
return impl->makeError(-1, "Curl not initialized");
256+
log::error("Failed to initialize cURL");
257+
return impl->makeError(-1, "Failed to initialize curl");
256258
}
257259

258260
// todo: in the future, we might want to support downloading directly into
@@ -329,8 +331,8 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
329331
}
330332

331333
// Cert verification
332-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, impl->m_certVerification ? 1 : 0);
333-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
334+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, impl->m_certVerification ? 1L : 0L);
335+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
334336

335337
if (impl->m_certVerification) {
336338
curl_blob caBundleBlob = {};
@@ -399,7 +401,7 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
399401
curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, impl->m_ignoreContentLength ? 1L : 0L);
400402

401403
// Track progress
402-
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
404+
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
403405

404406
// don't change the method from POST to GET when following a redirect
405407
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
@@ -476,10 +478,13 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
476478
// Check if the request failed on curl's side or because of cancellation
477479
if (curlResponse != CURLE_OK) {
478480
if (hasBeenCancelled()) {
481+
log::debug("Request cancelled");
479482
return WebTask::Cancel();
480483
}
481484
else {
482-
return impl->makeError(-1, "Curl failed: " + std::string(curl_easy_strerror(curlResponse)));
485+
std::string const err = curl_easy_strerror(curlResponse);
486+
log::error("cURL failure, error: {}", err);
487+
return impl->makeError(-1, "Curl failed: " + err);
483488
}
484489
}
485490

@@ -490,7 +495,7 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
490495

491496
// Otherwise resolve with success :-)
492497
return std::move(responseData.response);
493-
}, fmt::format("{} request to {}", method, url));
498+
}, fmt::format("{} {}", method, url));
494499
}
495500
WebTask WebRequest::post(std::string_view url) {
496501
return this->send("POST", url);

0 commit comments

Comments
 (0)