%PDF- %PDF-
Direktori : /var/www/html/o91-api/app/Exceptions/ |
Current File : /var/www/html/o91-api/app/Exceptions/Handler.php |
<?php namespace App\Exceptions; use App\Http\Controllers\Api\ApiController; use Exception; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Session\TokenMismatchException; use Illuminate\Validation\ValidationException; use Spatie\Permission\Exceptions\UnauthorizedException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; class Handler extends ExceptionHandler { /** * A list of the exception types that are not reported. * * @var array */ protected $dontReport = [ AuthenticationException::class, AuthorizationException::class, ModelNotFoundException::class, TokenMismatchException::class, UnauthorizedException::class, ValidationException::class, ApiException::class, ]; /** * 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 \Exception $exception * * @return void * @throws Exception */ public function report(Exception $exception) { parent::report($exception); } /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * * @return \Illuminate\Http\Response */ public function render($request, Exception $exception) { if ($exception instanceof UnauthorizedException) { return app(ApiController::class)->unauthorized([ 'message' => trans('auth.unauthorized'), ]); } if ($exception instanceof MethodNotAllowedHttpException) { return app(ApiController::class)->methodNotAllowed(); } if ($exception instanceof ModelNotFoundException) { $model = last(explode("\\", $exception->getModel())); return app(ApiController::class)->notFound([ 'message' => trans('exceptions.no_query_result_for_model', [ 'model' => $model, ]), ]); } return parent::render($request, $exception); } }