diff --git a/r5net/src/r5net.cpp b/r5net/src/r5net.cpp index 5a901949..6afa0130 100644 --- a/r5net/src/r5net.cpp +++ b/r5net/src/r5net.cpp @@ -51,9 +51,25 @@ std::vector R5Net::Client::GetServersList(std::string& outMessage else { if (res) + { + if (!res->body.empty()) + { + nlohmann::json resBody = nlohmann::json::parse(res->body); + + if (resBody["err"].is_string()) + outMessage = resBody["err"].get(); + else + outMessage = std::string("Failed to reach comp-server ") + std::to_string(res->status); + + return list; + } + outMessage = std::string("Failed to reach comp-server ") + std::to_string(res->status); - else - outMessage = "Failed to reach comp-server unknown error code."; + return list; + } + + outMessage = "failed to reach comp-server unknown error code."; + return list; } return list; @@ -90,7 +106,7 @@ bool R5Net::Client::PostServerHost(std::string& outMessage, std::string& outToke if (resBody["token"].is_string()) outToken = resBody["token"].get(); else - outToken = ""; + outToken = std::string(); return true; } @@ -107,12 +123,27 @@ bool R5Net::Client::PostServerHost(std::string& outMessage, std::string& outToke else { if (res) + { + if (!res->body.empty()) + { + nlohmann::json resBody = nlohmann::json::parse(res->body); + + if (resBody["err"].is_string()) + outMessage = resBody["err"].get(); + else + outMessage = std::string("Failed to reach comp-server ") + std::to_string(res->status); + + outToken = std::string(); + return false; + } + + outToken = std::string(); outMessage = std::string("Failed to reach comp-server ") + std::to_string(res->status); - else - outMessage = "Failed to reach comp-server unknown error code."; - - outToken = ""; + return false; + } + outToken = std::string(); + outMessage = "failed to reach comp-server unknown error code."; return false; } @@ -175,7 +206,7 @@ bool R5Net::Client::GetServerByToken(ServerListing& outServer, std::string& outM if (resBody["err"].is_string()) outMessage = resBody["err"].get(); else - outMessage = "Failed to reach comp-server unknown error code."; + outMessage = std::string("Failed to reach comp-server ") + std::to_string(res->status); return false; }