refactor: extract exception and cache middleware (#4248)

This commit is contained in:
Dag 2024-09-01 21:48:14 +02:00 committed by GitHub
parent 36fd72c87e
commit a6bdc322b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 99 additions and 56 deletions

View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
class ExceptionMiddleware implements Middleware
{
private Logger $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
public function __invoke(Request $request, $next): Response
{
try {
return $next($request);
} catch (\Throwable $e) {
$this->logger->error('Exception in ExceptionMiddleware', ['e' => $e]);
return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 500);
}
}
}