inti project

This commit is contained in:
root
2026-05-29 04:33:03 -04:00
commit cdeab1796f
699 changed files with 20516 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);
namespace App\Support\Api;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
final class ApiExceptionRenderer
{
public function render(Throwable $e): JsonResponse
{
if ($e instanceof ValidationException) {
return ApiResponse::error('Validation failed.', 422, $e->errors());
}
if ($e instanceof AuthenticationException) {
return ApiResponse::error('Unauthenticated.', 401);
}
if ($e instanceof AuthorizationException) {
return ApiResponse::error('Forbidden.', 403);
}
if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException || str_contains($e::class, 'NotFound')) {
return ApiResponse::error('Resource not found.', 404);
}
if (str_contains($e::class, 'Conflict') || str_contains($e::class, 'Duplicate')) {
return ApiResponse::error('Conflict.', 409);
}
if (str_contains($e::class, 'Unauthorized')) {
return ApiResponse::error('Forbidden.', 403);
}
if (str_contains($e::class, 'Exception')) {
report($e);
}
return ApiResponse::error('Server error.', 500);
}
}