Updated the sendHttpQuery method to now return an error code which tells the line corresponding to the return of the failure

This commit is contained in:
Th3maz1ng 2022-04-09 19:10:18 +02:00
parent 32e32e46d2
commit e3cdaafd88
2 changed files with 11 additions and 11 deletions

View File

@ -73,7 +73,7 @@ boolean HttpClient::connectByHostOrIp()
return _connectionStatus == SUCCESSFUL; return _connectionStatus == SUCCESSFUL;
} }
boolean HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData) int HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
{ {
if(resource != NULL) //We overwrite the resource if it has been already defined if(resource != NULL) //We overwrite the resource if it has been already defined
{ {
@ -88,7 +88,7 @@ boolean HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method
return sendHttpQuery(method, getData, postData, headerData); return sendHttpQuery(method, getData, postData, headerData);
} }
boolean HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData) int HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<DictionaryHelper::StringEntity> *getData, Dictionary<DictionaryHelper::StringEntity> *postData, Dictionary<DictionaryHelper::StringEntity> *headerData)
{ {
//We reset this two flags //We reset this two flags
_httpCode = HTTP_CODE::UNDEFINED_CODE; _httpCode = HTTP_CODE::UNDEFINED_CODE;
@ -101,7 +101,7 @@ boolean HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<Dictionar
if(!connected() || _connectionStatus == FAILED) if(!connected() || _connectionStatus == FAILED)
{ {
if(_retries == _maxRetries) return false; if(_retries == _maxRetries) return -__LINE__;
if(_connectionStatus == FAILED) if(_connectionStatus == FAILED)
{ {
@ -116,16 +116,16 @@ boolean HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<Dictionar
Serial.printf("We start a new connection : %s port %u\nretries : %u\n", _pAddress, _port, _retries); Serial.printf("We start a new connection : %s port %u\nretries : %u\n", _pAddress, _port, _retries);
#endif #endif
connectByHostOrIp(); if(!connectByHostOrIp())
if(_connectionStatus == FAILED)
{ {
#ifdef DEBUG_HTTP_CLIENT #ifdef DEBUG_HTTP_CLIENT
Serial.printf("Failed to reconnect\n"); Serial.printf("Failed to reconnect\n");
#endif #endif
stop(); stop();
return false; return -__LINE__;
} }
else
_retries = 0;
} }
if(connected()) if(connected())
@ -156,12 +156,12 @@ boolean HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary<Dictionar
Serial.printf("Http verb unspecified\n", status()); Serial.printf("Http verb unspecified\n", status());
#endif #endif
if(!_keepAlive)stop(); if(!_keepAlive)stop();
return false; return -__LINE__;
break; break;
} }
} }
return true; return 0;
} }
HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout) HttpClient::HTTP_CODE HttpClient::isReplyAvailable(uint16_t timeout)

View File

@ -25,13 +25,13 @@ class HttpClient : public WiFiClient, public HttpConstants
HttpClient(const HttpClient &object); HttpClient(const HttpClient &object);
virtual ~HttpClient(); virtual ~HttpClient();
boolean sendHttpQuery(const char *ressource, int sendHttpQuery(const char *ressource,
HttpRequestMethod method = HttpRequestMethod::GET, HttpRequestMethod method = HttpRequestMethod::GET,
Dictionary<DictionaryHelper::StringEntity> *getData = NULL, Dictionary<DictionaryHelper::StringEntity> *getData = NULL,
Dictionary<DictionaryHelper::StringEntity> *postData = NULL, Dictionary<DictionaryHelper::StringEntity> *postData = NULL,
Dictionary<DictionaryHelper::StringEntity> *headerData = NULL); Dictionary<DictionaryHelper::StringEntity> *headerData = NULL);
boolean sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET, int sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET,
Dictionary<DictionaryHelper::StringEntity> *getData = NULL, Dictionary<DictionaryHelper::StringEntity> *getData = NULL,
Dictionary<DictionaryHelper::StringEntity> *postData = NULL, Dictionary<DictionaryHelper::StringEntity> *postData = NULL,
Dictionary<DictionaryHelper::StringEntity> *headerData = NULL); Dictionary<DictionaryHelper::StringEntity> *headerData = NULL);