mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
add errorToString function
This commit is contained in:
parent
1dabac60a9
commit
b1e3d2256a
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -147,6 +147,8 @@ class HTTPClient {
|
||||
int writeToStream(Stream * stream);
|
||||
String getString(void);
|
||||
|
||||
String errorToString(int error);
|
||||
|
||||
protected:
|
||||
|
||||
struct RequestArgument {
|
||||
|
Loading…
x
Reference in New Issue
Block a user