feat: implement exception handling system with error context and policies
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user