core: Add an option to suppress error reporting (#1179)
Error reporting currently takes place for each error. This can result in many error messages if a server has connectivity issues (i.e. when it re-connects to the internet every 24 hours). This commit adds a new option to the configuration file to define the number of error reports to suppress before returning an error message to the user. Error reports are cached and therefore automatically purged after 24 hours. A successful bridge request does **not** clear the error count as sporadic issues can be the result of actual problems on the server. The implementation currently makes no assumption on the type of error, which means it also suppresses bridge errors in debug mode. The default value is, however, set to 1 which means all errors are reported. References #994
This commit is contained in:
parent
e8536ac1b2
commit
1022b5fdf9
4 changed files with 100 additions and 55 deletions
|
@ -146,6 +146,7 @@ class DisplayAction extends ActionAbstract {
|
|||
} catch(Error $e) {
|
||||
error_log($e);
|
||||
|
||||
if(logBridgeError($bridge::NAME, $e->getCode()) >= Configuration::getConfig('error', 'report_limit')) {
|
||||
if(Configuration::getConfig('error', 'output') === 'feed') {
|
||||
$item = new \FeedItem();
|
||||
|
||||
|
@ -183,9 +184,11 @@ class DisplayAction extends ActionAbstract {
|
|||
header('Content-Type: text/html', true, $e->getCode());
|
||||
die(buildTransformException($e, $bridge));
|
||||
}
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
error_log($e);
|
||||
|
||||
if(logBridgeError($bridge::NAME, $e->getCode()) >= Configuration::getConfig('error', 'report_limit')) {
|
||||
if(Configuration::getConfig('error', 'output') === 'feed') {
|
||||
$item = new \FeedItem();
|
||||
|
||||
|
@ -214,6 +217,7 @@ class DisplayAction extends ActionAbstract {
|
|||
die(buildTransformException($e, $bridge));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store data in cache
|
||||
$cache->saveData(array(
|
||||
|
|
|
@ -70,6 +70,9 @@ password = ""
|
|||
; "none" = No errors are reported
|
||||
output = "feed"
|
||||
|
||||
; Defines how often an error must occur before it is reported to the user
|
||||
report_limit = 1
|
||||
|
||||
; --- Cache specific configuration ---------------------------------------------
|
||||
|
||||
[SQLiteCache]
|
||||
|
|
|
@ -204,6 +204,10 @@ final class Configuration {
|
|||
if(!is_string(self::getConfig('error', 'output')))
|
||||
self::reportConfigurationError('error', 'output', 'Is not a valid String');
|
||||
|
||||
if(!is_numeric(self::getConfig('error', 'report_limit'))
|
||||
|| self::getConfig('error', 'report_limit') < 1)
|
||||
self::reportConfigurationError('admin', 'report_limit', 'Value is invalid');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,3 +41,37 @@ function returnClientError($message){
|
|||
function returnServerError($message){
|
||||
returnError($message, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores bridge-specific errors in a cache file.
|
||||
*
|
||||
* @param string $bridgeName The name of the bridge that failed.
|
||||
* @param int $code The error code
|
||||
*
|
||||
* @return int The total number the same error has appeared
|
||||
*/
|
||||
function logBridgeError($bridgeName, $code) {
|
||||
$cacheFac = new CacheFactory();
|
||||
$cacheFac->setWorkingDir(PATH_LIB_CACHES);
|
||||
|
||||
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
|
||||
$cache->setScope('error_reporting');
|
||||
$cache->setkey($bridgeName . '_' . $code);
|
||||
$cache->purgeCache(86400); // 24 hours
|
||||
|
||||
if($report = $cache->loadData()) {
|
||||
$report = json_decode($report, true);
|
||||
$report['time'] = time();
|
||||
$report['count']++;
|
||||
} else {
|
||||
$report = array(
|
||||
'error' => $code,
|
||||
'time' => time(),
|
||||
'count' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
$cache->saveData(json_encode($report));
|
||||
|
||||
return $report['count'];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue