feat: error callback in network.get, .get_binary, .post

This commit is contained in:
MihailRis
2025-04-30 19:15:39 +03:00
parent 76fb2e42d3
commit 556a561f1c
3 changed files with 39 additions and 8 deletions
+7 -4
View File
@@ -30,6 +30,9 @@ using SOCKET = int;
using namespace network;
inline constexpr int HTTP_OK = 200;
inline constexpr int HTTP_BAD_GATEWAY = 502;
static debug::Logger logger("network");
static size_t write_callback(
@@ -149,7 +152,7 @@ public:
auto message = curl_multi_strerror(res);
logger.error() << message << " (" << url << ")";
if (onReject) {
onReject(message);
onReject(HTTP_BAD_GATEWAY);
}
url = "";
}
@@ -164,7 +167,7 @@ public:
auto message = curl_multi_strerror(res);
logger.error() << message << " (" << url << ")";
if (onReject) {
onReject(message);
onReject(HTTP_BAD_GATEWAY);
}
curl_multi_remove_handle(multiHandle, curl);
url = "";
@@ -176,7 +179,7 @@ public:
}
int response;
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &response);
if (response == 200) {
if (response == HTTP_OK) {
long size;
if (!curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &size)) {
totalUpload += size;
@@ -191,7 +194,7 @@ public:
} else {
logger.error() << "response code " << response << " (" << url << ")";
if (onReject) {
onReject(std::to_string(response).c_str());
onReject(response);
}
}
url = "";
+1 -1
View File
@@ -11,7 +11,7 @@
namespace network {
using OnResponse = std::function<void(std::vector<char>)>;
using OnReject = std::function<void(const char*)>;
using OnReject = std::function<void(int)>;
class Requests {
public: