fix: improve error handling in OTA upload process
This commit is contained in:
parent
ef9ef7257a
commit
0500bb6951
10
src/ota.cpp
10
src/ota.cpp
@ -43,11 +43,13 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
|
|||||||
|
|
||||||
// Schreibe Daten
|
// Schreibe Daten
|
||||||
if (Update.write(data, len) != len) {
|
if (Update.write(data, len) != len) {
|
||||||
Update.printError(Serial);
|
|
||||||
String errorMsg = Update.errorString();
|
String errorMsg = Update.errorString();
|
||||||
|
if (errorMsg != "No Error") {
|
||||||
|
Update.printError(Serial);
|
||||||
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentOffset += len;
|
currentOffset += len;
|
||||||
|
|
||||||
@ -59,8 +61,14 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = Update.errorString();
|
String errorMsg = Update.errorString();
|
||||||
|
if (errorMsg != "No Error") {
|
||||||
Update.printError(Serial);
|
Update.printError(Serial);
|
||||||
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Update failed: " + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Update failed: " + errorMsg + "\"}");
|
||||||
|
} else {
|
||||||
|
request->send(200, "application/json", "{\"status\":\"success\",\"message\":\"Update successful! Device will restart...\",\"restart\":true}");
|
||||||
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user