feat: add a proper feed item uid when the bridge errors out (#3237)

* refactor: move function to class

* fix: use the computed bridge name as cache key

* refactor: extract method

* fix: set a feed item uid on errors

* docs

* fix: remove year from uid
This commit is contained in:
Dag 2023-02-02 22:53:01 +01:00 committed by GitHub
parent c97e1923ae
commit 7f1b32f390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 67 deletions

View file

@ -45,37 +45,3 @@ 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)
{
$cacheFactory = new CacheFactory();
$cache = $cacheFactory->create();
$cache->setScope('error_reporting');
$cache->setkey($bridgeName . '_' . $code);
$cache->purgeCache(86400); // 24 hours
if ($report = $cache->loadData()) {
$report = Json::decode($report);
$report['time'] = time();
$report['count']++;
} else {
$report = [
'error' => $code,
'time' => time(),
'count' => 1,
];
}
$cache->saveData(Json::encode($report));
return $report['count'];
}