mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
httpUpdate Improve error handling
This commit is contained in:
@ -120,6 +120,12 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
|
|||||||
int code = http->GET();
|
int code = http->GET();
|
||||||
int len = http->getSize();
|
int len = http->getSize();
|
||||||
|
|
||||||
|
if(code <= 0) {
|
||||||
|
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http->errorToString(code).c_str());
|
||||||
|
http->end();
|
||||||
|
return HTTP_UPDATE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
|
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
|
||||||
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
|
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
|
||||||
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
|
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
|
||||||
@ -138,7 +144,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(code) {
|
switch(code) {
|
||||||
case 200: ///< OK (Start Update)
|
case HTTP_CODE_OK: ///< OK (Start Update)
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
bool startUpdate = false;
|
bool startUpdate = false;
|
||||||
if(spiffs) {
|
if(spiffs) {
|
||||||
@ -192,19 +198,18 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
|
|||||||
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n");
|
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 304:
|
case HTTP_CODE_NOT_MODIFIED:
|
||||||
///< Not Modified (No updates)
|
///< Not Modified (No updates)
|
||||||
ret = HTTP_UPDATE_NO_UPDATES;
|
ret = HTTP_UPDATE_NO_UPDATES;
|
||||||
break;
|
break;
|
||||||
case 403:
|
|
||||||
///< Forbidden
|
|
||||||
// todo handle login
|
|
||||||
default:
|
default:
|
||||||
ret = HTTP_UPDATE_FAILED;
|
ret = HTTP_UPDATE_FAILED;
|
||||||
DEBUG_HTTP_UPDATE("[httpUpdate] Code is (%d)\n", code);
|
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code);
|
||||||
|
//http->writeToStream(&Serial1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
http->end();
|
http->end();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user