From 04243860ce0c224fa81063b62e4b9e852a29be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 12 Aug 2026 17:26:31 +0200 Subject: [PATCH] refactor(api): simplify exception handling in app configuration Removed custom exception handling logic and replaced it with a reference to the existing exceptions file. --- bootstrap/app.php | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 0ae9ceb..f1e24fc 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -4,11 +4,7 @@ declare(strict_types=1); use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; -use Illuminate\Http\Request; use Illuminate\Support\Env; -use Presentation\Api\Exceptions\ApiExceptionDispatcher; -use Presentation\Web\Exceptions\WebExceptionRenderer; -use Sentry\State\HubInterface; return Application::configure(Env::get('APP_BASE_PATH', dirname(__DIR__))) ->withRouting( @@ -18,28 +14,5 @@ return Application::configure(Env::get('APP_BASE_PATH', dirname(__DIR__))) health: '/up', ) ->withMiddleware(require __DIR__ . '/middlewares.php') - ->withExceptions(function (Exceptions $exceptions): void { - $exceptions->reportable(function (\Throwable $e): void { - if (app()->bound(HubInterface::class)) { - resolve(HubInterface::class)->captureException($e); - } - }); - - $exceptions->render(function (\Throwable $e, Request $request) { - $apiDispatcher = resolve(ApiExceptionDispatcher::class); - if ($apiResponse = $apiDispatcher->render($e, $request)) { - return $apiResponse; - } - - $webRenderer = resolve(WebExceptionRenderer::class); - if ($webResponse = $webRenderer->render($e, $request)) { - return $webResponse; - } - - return null; - }); - - $exceptions->shouldRenderJsonWhen( - fn (Request $request) => $request->is('api/*'), - ); - })->create(); + ->withExceptions(require __DIR__ . '/exceptions.php') + ->create();