From 939836b5bb25013907c4bd08f182fa0edee3d838 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 3 Oct 2021 12:25:18 +0800 Subject: [PATCH] Show more useful error on login failure --- nel/include/nel/web/http_client_curl.h | 4 ++++ nel/src/web/http_client_curl.cpp | 8 +++++--- ryzom/client/src/login.cpp | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nel/include/nel/web/http_client_curl.h b/nel/include/nel/web/http_client_curl.h index cfb1ac38a..babd0d7f9 100644 --- a/nel/include/nel/web/http_client_curl.h +++ b/nel/include/nel/web/http_client_curl.h @@ -63,6 +63,8 @@ public: /// Disconnect if connected (otherwise does nothing) void disconnect(); + const char *lastError() { return &m_ErrorBuf[0]; } + protected: /// Helper @@ -78,6 +80,8 @@ private: std::vector _ReceiveBuffer; std::string _Auth; // must be kept here because curl only stores the char pointer + + std::vector m_ErrorBuf; }; extern CCurlHttpClient CurlHttpClient; diff --git a/nel/src/web/http_client_curl.cpp b/nel/src/web/http_client_curl.cpp index b0ea66de3..446491768 100644 --- a/nel/src/web/http_client_curl.cpp +++ b/nel/src/web/http_client_curl.cpp @@ -124,15 +124,17 @@ bool CCurlHttpClient::sendRequest(const std::string& methodWB, const std::string curl_easy_setopt(_Curl, CURLOPT_WRITEFUNCTION, CCurlHttpClient::writeDataFromCurl); curl_easy_setopt(_Curl, CURLOPT_WRITEDATA, this); - char errorbuf [CURL_ERROR_SIZE+1]; - curl_easy_setopt(_Curl, CURLOPT_ERRORBUFFER, errorbuf); + if (!m_ErrorBuf.size()) + m_ErrorBuf.resize(CURL_ERROR_SIZE + 1); + m_ErrorBuf[0] = '\0'; + curl_easy_setopt(_Curl, CURLOPT_ERRORBUFFER, &m_ErrorBuf[0]); // Send CURLcode res = curl_easy_perform(_Curl); if (res != 0) { if (verbose) - nlwarning(errorbuf); + nlwarning(&m_ErrorBuf[0]); return false; } diff --git a/ryzom/client/src/login.cpp b/ryzom/client/src/login.cpp index bedd66f7c..9502120c5 100644 --- a/ryzom/client/src/login.cpp +++ b/ryzom/client/src/login.cpp @@ -2832,7 +2832,7 @@ string checkLogin(const string &login, const string &password, const string &cli { // ask server for salt if(!HttpClient.sendGet(url + "?cmd=ask&cp=2&login=" + login + "&lg=" + ClientCfg.LanguageCode, "", pPM->isVerboseLog())) - return "Can't send (error code 60)"; + return std::string("Can't send (error code 60) ") + HttpClient.lastError(); if(pPM->isVerboseLog()) nlinfo("Sent request for password salt");