feat: implement exception handling system with error context and policies

This commit is contained in:
2025-11-01 15:46:43 +01:00
parent f3440dff0d
commit a441da37f6
35 changed files with 920 additions and 88 deletions

View File

@@ -6,6 +6,7 @@ namespace App\Framework\Http;
use App\Framework\DI\Container;
use App\Framework\Logging\Logger;
use App\Framework\Logging\ValueObjects\LogContext;
final readonly class HttpMiddlewareChain implements HttpMiddlewareChainInterface
{

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Framework\Http\Middlewares;
use App\Framework\ErrorHandling\ErrorHandler;
use App\Framework\ExceptionHandling\ErrorKernel;
use App\Framework\Http\HttpMiddleware;
use App\Framework\Http\MiddlewareContext;
use App\Framework\Http\MiddlewarePriority;
@@ -18,7 +19,7 @@ final readonly class ExceptionHandlingMiddleware implements HttpMiddleware
{
public function __construct(
private Logger $logger,
private ErrorHandler $errorHandler,
#private ErrorHandler $errorHandler,
) {
}
@@ -27,6 +28,10 @@ final readonly class ExceptionHandlingMiddleware implements HttpMiddleware
try {
return $next($context);
} catch (\Throwable $e) {
$error = new ErrorKernel();
$error->handle($e);
$response = $this->errorHandler->createHttpResponse($e, $context);
return $context->withResponse($response);