From 043dabaccff6ed8a35d12400ed812c9f067ed2fa Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 23 Dec 2016 21:44:52 +0800 Subject: [PATCH] add error handler of rendering exceptions in brief --- app/Exceptions/Handler.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7bbacbdd..094c41b2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -72,17 +72,18 @@ class Handler extends ExceptionHandler return $e->getResponse()->setStatusCode(200); } - // render exceptions with whoops - if (config('app.debug')) { - foreach ($this->dontReport as $type) { - if ($e instanceof $type) { - return parent::render($request, $e); + foreach ($this->dontReport as $type) { + if ($e instanceof $type) { + return parent::render($request, $e); + } else { + // hide exception details if not in debug mode + if (config('app.debug')) { + return $this->renderExceptionWithWhoops($e); + } else { + return $this->renderExceptionInBrief($e); } } - return $this->renderExceptionWithWhoops($e); } - - return response()->view('errors.brief', ['code' => 0, 'message' => 'cmn']); } /** @@ -104,4 +105,15 @@ class Handler extends ExceptionHandler $e->getHeaders() ); } + + /** + * Render an exception in a short word. + * + * @param \Exception $e + * @return \Illuminate\Http\Response + */ + protected function renderExceptionInBrief(Exception $e) + { + return response()->view('errors.brief'); + } }