1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

add errorToString function

This commit is contained in:
Markus Sattler 2015-12-09 13:01:08 +01:00
parent 1dabac60a9
commit b1e3d2256a
5 changed files with 32 additions and 3 deletions

View File

@ -61,7 +61,7 @@ void loop() {
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();

View File

@ -56,7 +56,7 @@ void loop() {
http.writeToStream(&USE_SERIAL);
}
} else {
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();

View File

@ -90,7 +90,7 @@ void loop() {
}
} else {
USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();

View File

@ -454,6 +454,33 @@ String HTTPClient::getString(void) {
return sstring;
}
/**
* converts error code to String
* @param error int
* @return String
*/
String HTTPClient::errorToString(int error) {
switch(error) {
case HTTPC_ERROR_CONNECTION_REFUSED:
return String("connection refused");
case HTTPC_ERROR_SEND_HEADER_FAILED:
return String("send header failed");
case HTTPC_ERROR_SEND_PAYLOAD_FAILED:
return String("send payload failed");
case HTTPC_ERROR_NOT_CONNECTED:
return String("not connected");
case HTTPC_ERROR_CONNECTION_LOST:
return String("connection lost");
case HTTPC_ERROR_NO_STREAM:
return String("no stream");
case HTTPC_ERROR_NO_HTTP_SERVER:
return String("no HTTP server");
default:
return String();
}
}
/**
* adds Header to the request
* @param name

View File

@ -147,6 +147,8 @@ class HTTPClient {
int writeToStream(Stream * stream);
String getString(void);
String errorToString(int error);
protected:
struct RequestArgument {