Further work on better logging

This commit is contained in:
Pinga 2025-02-14 20:50:49 +02:00
parent 595d10349c
commit 2adce55a07
6 changed files with 69 additions and 78 deletions

View file

@ -52,7 +52,17 @@ $log->info('server started.');
// Handle incoming HTTP requests
$http->on('request', function ($request, $response) use ($c, $pool, $log, $rateLimiter) {
// Get a PDO connection from the pool
$pdo = $pool->get();
try {
$pdo = $pool->get();
if (!$pdo) {
throw new PDOException("Failed to retrieve a connection from Swoole PDOPool.");
}
} catch (PDOException $e) {
$log->alert("Swoole PDO Pool failed: " . $e->getMessage());
$response->header('Content-Type', 'application/json');
$response->status(500);
$response->end(json_encode(['error' => 'Database failure. Please try again later.']));
}
$remoteAddr = $request->server['remote_addr'];
if (!isIpWhitelisted($remoteAddr, $pdo)) {