Skip to content

Commit 52f4cc8

Browse files
authored
httpclient: fix error meaning (#7401)
* httpclient: fix error meaning * deprecate HTTPC_ERROR_CONNECTION_REFUSED
1 parent 00fc716 commit 52f4cc8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s
679679

680680
// connect to server
681681
if(!connect()) {
682-
return returnError(HTTPC_ERROR_CONNECTION_REFUSED);
682+
return returnError(HTTPC_ERROR_CONNECTION_FAILED);
683683
}
684684

685685
addHeader(F("Content-Length"), String(payload && size > 0 ? size : 0));
@@ -793,7 +793,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
793793

794794
// connect to server
795795
if(!connect()) {
796-
return returnError(HTTPC_ERROR_CONNECTION_REFUSED);
796+
return returnError(HTTPC_ERROR_CONNECTION_FAILED);
797797
}
798798

799799
if(size > 0) {
@@ -1083,8 +1083,8 @@ const String& HTTPClient::getString(void)
10831083
String HTTPClient::errorToString(int error)
10841084
{
10851085
switch(error) {
1086-
case HTTPC_ERROR_CONNECTION_REFUSED:
1087-
return F("connection refused");
1086+
case HTTPC_ERROR_CONNECTION_FAILED:
1087+
return F("connection failed");
10881088
case HTTPC_ERROR_SEND_HEADER_FAILED:
10891089
return F("send header failed");
10901090
case HTTPC_ERROR_SEND_PAYLOAD_FAILED:

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000)
4949

5050
/// HTTP client errors
51-
#define HTTPC_ERROR_CONNECTION_REFUSED (-1)
51+
#define HTTPC_ERROR_CONNECTION_FAILED (-1)
5252
#define HTTPC_ERROR_SEND_HEADER_FAILED (-2)
5353
#define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3)
5454
#define HTTPC_ERROR_NOT_CONNECTED (-4)
@@ -60,6 +60,8 @@
6060
#define HTTPC_ERROR_STREAM_WRITE (-10)
6161
#define HTTPC_ERROR_READ_TIMEOUT (-11)
6262

63+
constexpr int HTTPC_ERROR_CONNECTION_REFUSED __attribute__((deprecated)) = HTTPC_ERROR_CONNECTION_FAILED;
64+
6365
/// size for the stream handling
6466
#define HTTP_TCP_BUFFER_SIZE (1460)
6567

0 commit comments

Comments
 (0)