chore(*): remove duplicate cache rule + cleanup cache headers; cleanup + formatting
This commit is contained in:
parent
425fed6ff6
commit
0e565970a5
42 changed files with 223 additions and 217 deletions
|
@ -31,13 +31,16 @@ abstract class BaseHandler
|
|||
try {
|
||||
$redis = new \Redis();
|
||||
$redis->connect("127.0.0.1", 6379);
|
||||
|
||||
$this->cache = $redis;
|
||||
} catch (\Exception $e) {
|
||||
error_log("Redis connection failed: " . $e->getMessage());
|
||||
|
||||
$this->cache = null;
|
||||
}
|
||||
} else {
|
||||
error_log("Redis extension not found — caching disabled.");
|
||||
|
||||
$this->cache = null;
|
||||
}
|
||||
}
|
||||
|
@ -56,12 +59,12 @@ abstract class BaseHandler
|
|||
], $options));
|
||||
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if (empty($responseBody)) return [];
|
||||
|
||||
$data = json_decode($responseBody, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \Exception("Invalid JSON: " . json_last_error_msg());
|
||||
}
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) throw new \Exception("Invalid JSON: " . json_last_error_msg());
|
||||
|
||||
return $data;
|
||||
} catch (RequestException $e) {
|
||||
|
@ -78,6 +81,7 @@ abstract class BaseHandler
|
|||
protected function fetchFromApi(string $endpoint, string $query = ""): array
|
||||
{
|
||||
$url = $endpoint . ($query ? "?{$query}" : "");
|
||||
|
||||
return $this->makeRequest("GET", $url);
|
||||
}
|
||||
|
||||
|
@ -85,7 +89,9 @@ abstract class BaseHandler
|
|||
{
|
||||
http_response_code($statusCode);
|
||||
header("Content-Type: application/json");
|
||||
|
||||
echo json_encode($data);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue