From 7e888f6408fd8537ad52cb09e07142edca963123 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 10 Dec 2022 16:09:47 +0100 Subject: [PATCH] Avoid blank page (NULL) as response --- src/web/WebAPIService.cpp | 11 +++++++++-- src/web/WebCustomizationService.cpp | 7 +++++++ src/web/WebDataService.cpp | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 0b4de5c36..a50b7148a 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -101,8 +101,15 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) { } // output json buffer - auto * response = new PrettyAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE_DYN); - JsonObject output = response->getRoot(); + auto * response = new PrettyAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE_DYN); + if (!response->getSize()) { + response = new PrettyAsyncJsonResponse(false, 256); + response->setCode(507); + response->setLength(); + request->send(response); // Insufficient Storage + return; + } + JsonObject output = response->getRoot(); // call command uint8_t return_code = Command::process(request->url().c_str(), is_admin, input, output); diff --git a/src/web/WebCustomizationService.cpp b/src/web/WebCustomizationService.cpp index 5a641e91a..d7b1d3c7e 100644 --- a/src/web/WebCustomizationService.cpp +++ b/src/web/WebCustomizationService.cpp @@ -201,6 +201,13 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) { void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) { if (json.is()) { auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXXLARGE_DYN); + if (!response->getSize()) { + response = new MsgpackAsyncJsonResponse(true, 256); + response->setCode(507); + response->setLength(); + request->send(response); // Insufficient Storage + return; + } for (const auto & emsdevice : EMSESP::emsdevices) { if (emsdevice->unique_id() == json["id"]) { #ifndef EMSESP_STANDALONE diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index bb886f790..c82855338 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -166,6 +166,14 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) { void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) { if (json.is()) { auto * response = new MsgpackAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXXLARGE_DYN); + if (!response->getSize()) { + // EMSESP::logger().err("Insufficient storage"); + response = new MsgpackAsyncJsonResponse(false, 256); + response->setCode(507); + response->setLength(); + request->send(response); // Insufficient Storage (507) + return; + } for (const auto & emsdevice : EMSESP::emsdevices) { if (emsdevice->unique_id() == json["id"]) { // wait max 2.5 sec for updated data (post_send_delay is 2 sec)