view('errors.FireflyException', ['exception' => $exception, 'debug' => $isDebug], 500); } return parent::render($request, $exception); } /** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param Exception $exception * * @return void */ public function report(Exception $exception) { if ($exception instanceof FireflyException || $exception instanceof ErrorException) { $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(), ]; // create job that will mail. $ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'; $job = new MailError($userData, env('SITE_OWNER', ''), $ip, $data); dispatch($job); } parent::report($exception); } /** * Convert an authentication exception into an unauthenticated response. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ protected function unauthenticated($request) { if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); } return redirect()->guest('login'); } }