improved errorhandler, send non fatal errors async

This commit is contained in:
kremsy 2017-05-17 13:05:05 +02:00
parent 85d9f28166
commit e393bf0b4f

View File

@ -2,6 +2,7 @@
namespace ManiaControl;
use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Plugins\PluginManager;
use ManiaControl\Update\UpdateManager;
use ManiaControl\Utils\Formatter;
@ -161,6 +162,8 @@ class ErrorHandler {
$info = base64_encode($json);
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
if ($isFatalError) {
$response = WebReader::getUrl($url);
$content = $response->getContent();
$success = json_decode($content);
@ -169,6 +172,25 @@ class ErrorHandler {
} else {
Logger::log('Error-Report failed! ' . print_r($content, true));
}
} else {
//Async Report
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
$asyncHttpRequest->setCallable(function ($json, $error) {
if ($error) {
Logger::logError("Error while Sending Error Report");
return;
}
$success = json_decode($json);
if ($success) {
Logger::log('Error-Report successful!');
} else {
Logger::log('Error-Report failed! ' . print_r($json, true));
}
});
$asyncHttpRequest->getData();
}
}
if ($isFatalError) {