From bf270745f0dc540aa72f9bbd7cc2f9df9c91cbd4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 Sep 2017 21:57:45 +0200 Subject: [PATCH] Separate commit for error handler. --- app/Exceptions/Handler.php | 109 ++++++------------------------------- 1 file changed, 17 insertions(+), 92 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 14cb6b0df5..c17d9d7ad2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -1,128 +1,53 @@ view('errors.FireflyException', ['exception' => $exception, 'debug' => $isDebug], 500); - } - - return parent::render($request, $exception); - } - + protected $dontFlash = [ + 'password', + 'password_confirmation', + ]; /** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param Exception $exception - * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five. - * + * @param \Exception $exception * @return void */ public function report(Exception $exception) { - $doMailError = env('SEND_ERROR_MESSAGE', true); - if (($exception instanceof FireflyException || $exception instanceof ErrorException) && $doMailError) { - $userData = [ - 'id' => 0, - 'email' => 'unknown@example.com', - ]; - if (auth()->check()) { - $userData['id'] = auth()->user()->id; - $userData['email'] = auth()->user()->email; - } - $data = [ - 'class' => get_class($exception), - 'errorMessage' => $exception->getMessage(), - 'time' => date('r'), - 'stackTrace' => $exception->getTraceAsString(), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - 'code' => $exception->getCode(), - 'version' => config('firefly.version'), - ]; - - // create job that will mail. - $ipAddress = Request::ip() ?? '0.0.0.0'; - $job = new MailError($userData, env('SITE_OWNER', ''), $ipAddress, $data); - dispatch($job); - } - parent::report($exception); } /** - * Convert an authentication exception into an unauthenticated response. + * Render an exception into an HTTP response. * - * @param $request - * - * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse + * @param \Illuminate\Http\Request $request + * @param \Exception $exception + * @return \Illuminate\Http\Response */ - protected function unauthenticated($request) + public function render($request, Exception $exception) { - if ($request->expectsJson()) { - return response()->json(['error' => 'Unauthenticated.'], 401); - } - - return redirect()->guest('login'); + return parent::render($request, $exception); } }