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:
parent
e92b042906
commit
04243860ce
1 changed files with 2 additions and 29 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue