handle bad_alloc for vedirect status

This commit is contained in:
helgeerbe 2023-04-04 18:17:53 +02:00
parent 98faffc3ca
commit 160b5b5b01

View File

@ -58,14 +58,16 @@ void WebApiWsVedirectLiveClass::loop()
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestVedirectTimestamp)) {
try {
String buffer;
// free JsonDocument as soon as possible
{
DynamicJsonDocument root(1024);
JsonVariant var = root;
generateJsonResponse(var);
String buffer;
if (buffer) {
serializeJson(root, buffer);
}
if (buffer) {
if (Configuration.get().Security_AllowReadonly) {
_ws.setAuthentication("", "");
} else {
@ -153,10 +155,18 @@ void WebApiWsVedirectLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}
try {
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
JsonVariant root = response->getRoot().as<JsonVariant>();
JsonVariant root = response->getRoot();
generateJsonResponse(root);
response->setLength();
request->send(response);
} catch (std::bad_alloc& bad_alloc) {
MessageOutput.printf("Call to /api/livedata/status temporarely out of resources. Reason: \"%s\".\r\n", bad_alloc.what());
WebApi.sendTooManyRequests(request);
}
}