mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 19:36:52 +03:00
2bbce8ebef
* refactor * fix: bug in previous refactor * chore: exclude phpcompat sniff due to bug in phpcompat * fix: do not leak absolute paths * refactor/fix: batch extensions checking, fix DOS issue
81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
|
|
* Atom feeds for websites that don't have one.
|
|
*
|
|
* For the full license information, please view the UNLICENSE file distributed
|
|
* with this source code.
|
|
*
|
|
* @package Core
|
|
* @license http://unlicense.org/ UNLICENSE
|
|
* @link https://github.com/rss-bridge/rss-bridge
|
|
*/
|
|
|
|
/**
|
|
* Throws an exception when called.
|
|
*
|
|
* @throws \Exception when called
|
|
* @param string $message The error message
|
|
* @param int $code The HTTP error code
|
|
* @link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes List of HTTP
|
|
* status codes
|
|
*/
|
|
function returnError($message, $code)
|
|
{
|
|
throw new \Exception($message, $code);
|
|
}
|
|
|
|
/**
|
|
* Returns HTTP Error 400 (Bad Request) when called.
|
|
*
|
|
* @param string $message The error message
|
|
*/
|
|
function returnClientError($message)
|
|
{
|
|
returnError($message, 400);
|
|
}
|
|
|
|
/**
|
|
* Returns HTTP Error 500 (Internal Server Error) when called.
|
|
*
|
|
* @param string $message The error 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)
|
|
{
|
|
$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'];
|
|
}
|