refactor(api): simplify exception handling in app configuration

Removed custom exception handling logic and replaced it with a reference to the existing exceptions file.
This commit is contained in:
Jérémy Munsch 2026-08-12 17:26:31 +02:00
parent e92b042906
commit 04243860ce
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4

View file

@ -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();