From 2db0ea6188f0ec631e0cf52985d7e52b658aa2cd Mon Sep 17 00:00:00 2001 From: Maksim Lanin Date: Mon, 10 Feb 2020 15:35:55 +0300 Subject: [PATCH] Remove views support. Let it be API everywhere --- src/ExceptionHandlerTrait.php | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/ExceptionHandlerTrait.php b/src/ExceptionHandlerTrait.php index 114296f..8f9a33c 100644 --- a/src/ExceptionHandlerTrait.php +++ b/src/ExceptionHandlerTrait.php @@ -16,7 +16,7 @@ trait ExceptionHandlerTrait * Report or log an exception. * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $e + * @param \Exception $e * @return void * @throws Exception */ @@ -36,41 +36,11 @@ public function render($request, Exception $e) { $e = $this->resolveException($e); - $response = $request->expectsJson() || ! function_exists('view') - ? $this->renderForApi($e, $request) - : $this->renderForHtml($e, $request); + $response = response()->json($this->formatApiResponse($e), $e->getCode(), $e->getHeaders()); return $response->withException($e); } - /** - * Render exceptions for json API. - * - * @param ApiException $e - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\JsonResponse - */ - protected function renderForApi(ApiException $e, $request) - { - return response()->json($this->formatApiResponse($e), $e->getCode(), $e->getHeaders()); - } - - /** - * Render exception for common html request. - * - * @param ApiException $e - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response - */ - protected function renderForHtml(ApiException $e, $request) - { - $status = $e->getCode(); - - return view()->exists("errors.{$status}") - ? response(view("errors.{$status}", ['exception' => $e]), $status, $e->getHeaders()) - : $this->renderForApi($e, $request); - } - /** * Define exception. *