Files
unified-restaurant-original/backend/app/Exceptions/Handler.php

38 lines
1.1 KiB
PHP

<?php
namespace App\Exceptions;
use Illuminate\Http\JsonResponse;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Throwable;
class Handler extends ExceptionHandler {
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
public function report(Throwable $exception) {
parent::report($exception);
}
public function render($request, Throwable $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());
}
}