Skip to content

Commit b1ea7b6

Browse files
committed
httpUpdate Improve error handling
1 parent ce4edcb commit b1ea7b6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
120120
int code = http->GET();
121121
int len = http->getSize();
122122

123+
if(code <= 0) {
124+
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http->errorToString(code).c_str());
125+
http->end();
126+
return HTTP_UPDATE_FAILED;
127+
}
128+
123129
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
124130
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
125131
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
@@ -138,7 +144,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
138144
}
139145

140146
switch(code) {
141-
case 200: ///< OK (Start Update)
147+
case HTTP_CODE_OK: ///< OK (Start Update)
142148
if(len > 0) {
143149
bool startUpdate = false;
144150
if(spiffs) {
@@ -192,19 +198,18 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
192198
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n");
193199
}
194200
break;
195-
case 304:
201+
case HTTP_CODE_NOT_MODIFIED:
196202
///< Not Modified (No updates)
197203
ret = HTTP_UPDATE_NO_UPDATES;
198204
break;
199-
case 403:
200-
///< Forbidden
201-
// todo handle login
202205
default:
203206
ret = HTTP_UPDATE_FAILED;
204-
DEBUG_HTTP_UPDATE("[httpUpdate] Code is (%d)\n", code);
207+
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code);
208+
//http->writeToStream(&Serial1);
205209
break;
206210
}
207211

212+
208213
http->end();
209214

210215
return ret;

0 commit comments

Comments
 (0)