From 9d4edfc0f0f1d8add934e4c4ff023e3483f9fb20 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Tue, 4 Nov 2025 21:37:11 +0100 Subject: [PATCH] Moved an internally used enum only to the private section of the class, changed the return type of the sendHttpQuery function from int to an enum which gives more details and remove the usage of magic numbers (line at which the return occured) --- src/app/HttpClient.cpp | 12 ++++++------ src/app/HttpClient.h | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/HttpClient.cpp b/src/app/HttpClient.cpp index 16a7578..eb73492 100644 --- a/src/app/HttpClient.cpp +++ b/src/app/HttpClient.cpp @@ -86,7 +86,7 @@ boolean HttpClient::connectByHostOrIp() return _connectionStatus == SUCCESSFUL; } -int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary *getData, Dictionary *postData, Dictionary *headerData) +HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary *getData, Dictionary *postData, Dictionary *headerData) { if(resource != NULL) //We overwrite the resource if it has been already defined { @@ -101,7 +101,7 @@ int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Di return sendHttpQuery(method, getData, postData, headerData); } -int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary *getData, Dictionary *postData, Dictionary *headerData) +HttpClient::HttpQueryStatus HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary *getData, Dictionary *postData, Dictionary *headerData) { //We reset this two flags _httpCode = HTTP_CODE::UNDEFINED_CODE; @@ -117,7 +117,7 @@ int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary *getData = NULL, Dictionary *postData = NULL, Dictionary *headerData = NULL); - int sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET, + HttpQueryStatus sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET, Dictionary *getData = NULL, Dictionary *postData = NULL, Dictionary *headerData = NULL); @@ -46,6 +46,8 @@ class HttpClient : public WiFiClient, public HttpConstants uint16_t readHttpBody(uint8_t *buffer, uint32_t size); protected: private: + enum ConnectionStatus { NO_ATTEMPT = 0, SUCCESSFUL, FAILED }; + boolean connectByHostOrIp(); void sendUriWithGetParams(Dictionary *data); void sendPostData(Dictionary *data);