Avoid blank page (NULL) as response

This commit is contained in:
MichaelDvP
2022-12-10 16:09:47 +01:00
parent bba70ce852
commit 7e888f6408
3 changed files with 24 additions and 2 deletions

View File

@@ -102,6 +102,13 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
// output json buffer
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

View File

@@ -201,6 +201,13 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
if (json.is<JsonObject>()) {
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

View File

@@ -166,6 +166,14 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) {
if (json.is<JsonObject>()) {
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)