From 0500bb69516e3c3e8056805d07d1fc68f8eed35b Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Thu, 20 Feb 2025 11:13:49 +0100 Subject: [PATCH] fix: improve error handling in OTA upload process --- src/ota.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ota.cpp b/src/ota.cpp index 2c5b8b6..2676cea 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -43,10 +43,12 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind // Schreibe Daten if (Update.write(data, len) != len) { - Update.printError(Serial); String errorMsg = Update.errorString(); - request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}"); - return; + if (errorMsg != "No Error") { + Update.printError(Serial); + request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}"); + return; + } } currentOffset += len; @@ -59,8 +61,14 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind ESP.restart(); } else { String errorMsg = Update.errorString(); - Update.printError(Serial); - request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Update failed: " + errorMsg + "\"}"); + if (errorMsg != "No Error") { + Update.printError(Serial); + 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(); + } } } }