Edit File: Handler.php
<?php namespace App\Exceptions; use App\Traits\ApiTrait; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Support\Arr; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Throwable; class Handler extends ExceptionHandler { use ApiTrait; /** * 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 = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function render($request, Throwable $exception) { if ($request->is('api/*')) { if ($exception instanceof ModelNotFoundException) { return $this->failMsg(trans('response.404')); } elseif ($exception instanceof NotFoundHttpException) { return $this->failMsg(trans('response.404_not_found')); } elseif ($exception instanceof RouteNotFoundException) { return $this->unauthenticatedMsg(trans('response.unauthenticated'),419); }elseif ($exception instanceof AuthenticationException) { return $this->unauthenticatedMsg(trans('response.unauthenticated'),419); } } return parent::render($request, $exception); } protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson() ) { return $this->failMsg(trans('response.unauthenticated'),419); } $guard = Arr::get($exception->guards(),0); switch ($guard) { default: $login = 'dashboard/login'; break; } return redirect()->guest(url($login)); } public function register() { $this->reportable(function (Throwable $e) { }); } }
Back to File Manager