From 4f463eb446f5ebf561d42db0f6cb2bed8a43e517 Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:26:32 +0200 Subject: [PATCH] Fixed error message parsing in r5net. --- r5net/src/r5net.cpp | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/r5net/src/r5net.cpp b/r5net/src/r5net.cpp index 5a901949..cb2f5bb4 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; @@ -107,12 +123,24 @@ 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); + + return false; + } + 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; + } + outMessage = "failed to reach comp-server unknown error code."; return false; } @@ -175,7 +203,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; }