handle bad_alloc for vedirect status
This commit is contained in:
parent
98faffc3ca
commit
160b5b5b01
@ -58,23 +58,25 @@ void WebApiWsVedirectLiveClass::loop()
|
|||||||
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestVedirectTimestamp)) {
|
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestVedirectTimestamp)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String buffer;
|
||||||
|
// free JsonDocument as soon as possible
|
||||||
|
{
|
||||||
DynamicJsonDocument root(1024);
|
DynamicJsonDocument root(1024);
|
||||||
JsonVariant var = root;
|
JsonVariant var = root;
|
||||||
generateJsonResponse(var);
|
generateJsonResponse(var);
|
||||||
|
serializeJson(root, buffer);
|
||||||
String buffer;
|
}
|
||||||
if (buffer) {
|
|
||||||
serializeJson(root, buffer);
|
if (buffer) {
|
||||||
|
if (Configuration.get().Security_AllowReadonly) {
|
||||||
if (Configuration.get().Security_AllowReadonly) {
|
_ws.setAuthentication("", "");
|
||||||
_ws.setAuthentication("", "");
|
} else {
|
||||||
} else {
|
_ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password);
|
||||||
_ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ws.textAll(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ws.textAll(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (std::bad_alloc& bad_alloc) {
|
} catch (std::bad_alloc& bad_alloc) {
|
||||||
MessageOutput.printf("Call to /api/vedirectlivedata/status temporarely out of resources. Reason: \"%s\".\r\n", bad_alloc.what());
|
MessageOutput.printf("Call to /api/vedirectlivedata/status temporarely out of resources. Reason: \"%s\".\r\n", bad_alloc.what());
|
||||||
}
|
}
|
||||||
@ -153,10 +155,18 @@ void WebApiWsVedirectLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
|
|||||||
if (!WebApi.checkCredentialsReadonly(request)) {
|
if (!WebApi.checkCredentialsReadonly(request)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
|
try {
|
||||||
JsonVariant root = response->getRoot().as<JsonVariant>();
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
|
||||||
generateJsonResponse(root);
|
JsonVariant root = response->getRoot();
|
||||||
|
|
||||||
response->setLength();
|
generateJsonResponse(root);
|
||||||
request->send(response);
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user