ldc-arcadia-api/src/Presentation/Api/Exceptions/ApiExceptionDispatcher.php
Jérémy Munsch 33f3aaf37f
fix(api): correct condition for JSON request handling
Ensure proper handling of requests that expect JSON responses.
2026-08-12 17:30:36 +02:00

32 lines
839 B
PHP

<?php
declare(strict_types=1);
namespace Presentation\Api\Exceptions;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Presentation\Api\V1\Exceptions\ApiExceptionRenderer as V1ApiExceptionRenderer;
use Throwable;
final readonly class ApiExceptionDispatcher
{
public function __construct(
private V1ApiExceptionRenderer $v1Renderer,
) {
}
public function render(Throwable $e, Request $request): ?JsonResponse
{
if (! $request->is('api/*', 'api') && ! $request->wantsJson()) {
return null;
}
if ($request->is('api/v1/*') || $request->is('api/v1')) {
return $this->v1Renderer->render($e, $request);
}
// Fallback for unversioned api/* requests -> default to V1
return $this->v1Renderer->render($e, $request);
}
}