is('api/*')) { return $this->handleApiError($request, $exception); } if ($exception instanceof AbstractHttpException && $exception->getStatusCode() === 403) { return redirect()->guest('login'); } return parent::render($request, $exception); } /** * Handle errors in the API * * @param $request * @param \Exception $exception * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response */ private function handleApiError($request, Exception $exception) { Log::error('API Error', $exception->getTrace()); if ($exception instanceof AbstractHttpException) { return $exception->getResponse(); } /* * Not of the HttpException abstract class. Map these into */ if ($exception instanceof ModelNotFoundException || $exception instanceof NotFoundHttpException) { $error = new AssetNotFound($exception); return $error->getResponse(); } // Custom exceptions should be extending HttpException if ($exception instanceof SymfonyHttpException) { $error = new SymfonyException($exception); return $error->getResponse(); } // Create the detailed errors from the validation errors if ($exception instanceof IlluminateValidationException) { $error = new ValidationException($exception); return $error->getResponse(); } $error = new GenericExceptionAbstract($exception); return $error->getResponse(); } /** * Convert an authentication exception into an unauthenticated response. * * @param Request $request * @param AuthenticationException $exception * * @return \Illuminate\Http\Response */ protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson() || $request->is('api/*')) { $error = new Unauthenticated(); return $error->getResponse(); } return redirect()->guest('login'); } /** * Render the given HttpException. * * @param AbstractHttpException $e * * @return \Illuminate\Http\Response|Response */ protected function renderHttpException(HttpExceptionInterface $e) { $status = $e->getStatusCode(); view()->replaceNamespace('errors', [ resource_path('views/layouts/'.setting('general.theme', 'default').'/errors'), resource_path('views/errors'), __DIR__.'/views', ]); if (view()->exists("errors::{$status}")) { return response()->view("errors::{$status}", [ 'exception' => $e, 'SKIN_NAME' => setting('general.theme', 'default'), ], $status, $e->getHeaders()); } return $this->convertExceptionToResponse($e); } /** * Ignition error page integration */ protected function whoopsHandler() { try { return app(HandlerInterface::class); } catch (BindingResolutionException $e) { return parent::whoopsHandler(); } } }