ldc-mesbr-app/app/Exceptions/Handler.php
Jérémy Munsch 2d089c9978
- Update phpcs.xml
- composer require kwaadpepper/exception-handler
- composer require slevomat/coding-standard --dev
- composer update
2022-02-10 12:49:48 +01:00

67 lines
1.7 KiB
PHP

<?php
namespace App\Exceptions;
use App\Http\Resources\StatusResource;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Throwable $exception)
{
if ($request->wantsJson() && $exception instanceof ModelNotFoundException) {
return response()->json(new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Resource not found.']), 404);
}
// if ($exception instanceof \ErrorException) {
// $response = response()->view('errors.500', [], 500);
// return $this->toIlluminateResponse($response,$exception);
// }
return parent::render($request, $exception);
}
}