diff --git a/backend/app/Exceptions/Handler.php b/backend/app/Exceptions/Handler.php index c5d889f..4400b03 100644 --- a/backend/app/Exceptions/Handler.php +++ b/backend/app/Exceptions/Handler.php @@ -2,6 +2,7 @@ namespace App\Exceptions; +use Illuminate\Http\JsonResponse; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Validation\ValidationException; @@ -22,6 +23,15 @@ class Handler extends ExceptionHandler { } public function render($request, Throwable $exception) { - return parent::render($request, $exception); + $rendered = parent::render($request, $exception); + + if($rendered instanceof JsonResponse) { + return $rendered; + } + + return response()->json([ + 'error' => $rendered->getStatusCode(), + 'message' => $exception instanceof HttpException ? $exception->getMessage() : 'Server Error', + ], $rendered->getStatusCode()); } }