From 33c98a58ab3ddae656c58a3f272bc8b299cab8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Fri, 1 Sep 2017 21:51:34 +0200 Subject: [PATCH] Add Update error number to error message in web UI --- code/espurna/web.ino | 11 ++++++++++- code/html/custom.js | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 40baf2da..88af2778 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -1066,7 +1066,15 @@ int _onCertificate(void * arg, const char *filename, uint8_t **buf) { #endif void _onUpgrade(AsyncWebServerRequest *request) { - AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", Update.hasError() ? "FAIL" : "OK"); + + char buffer[10]; + if (Update.hasError()) { + sprintf_P(buffer, PSTR("OK")); + } else { + sprintf_P(buffer, PSTR("ERROR %d"), Update.getError()); + } + + AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", buffer); response->addHeader("Connection", "close"); if (!Update.hasError()) { _web_defer.once_ms(100, []() { @@ -1075,6 +1083,7 @@ void _onUpgrade(AsyncWebServerRequest *request) { }); } request->send(response); + } void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { diff --git a/code/html/custom.js b/code/html/custom.js index 4fb2fc93..5ed92837 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -113,7 +113,7 @@ function doUpgrade() { window.location = "/"; }, 5000); } else { - alert("There was an error trying to upload the new image, please try again."); + alert("There was an error trying to upload the new image, please try again (" + data + ")."); } },