/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { switch (get_class($e)) { case "Swift_TransportException": case "PDOException": $errorView = "errors.500_config"; break; case "ErrorException": $errorView = "errors.500"; break; case "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException": return abort(400); default: $errorView = false; break; } if ($errorView) { // This makes use of a Symfony error handler to make pretty traces. $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug')); $FlattenException = FlattenException::create($e); $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException); $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException); $response = response()->view($errorView, ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500); return $this->toIlluminateResponse($response, $e); } else { return parent::render($request, $e); } }
public function sendException($exception) { if (!$this->isErrorFromBot()) { $recipients = Config::get("error-emailer::to"); if (isset($recipients['address'])) { // this is a single recipient if ($recipients['address']) { $recipients = array($recipients); } else { $recipients = array(); } } if (sizeof($recipients) > 0) { if ($exception instanceof FlattenException) { $flattened = $exception; } else { $flattened = FlattenException::create($exception); } $handler = new ExceptionHandler(); $content = $handler->getContent($flattened); $model = array('trace' => $content, 'exception' => $exception, 'flattened' => $flattened); Mail::send(Config::get("error-emailer::error_template"), $model, function ($message) use($model, $recipients) { $subject = View::make(Config::get("error-emailer::subject_template"), $model)->render(); $message->subject($subject); foreach ($recipients as $to) { $message->to($to['address'], $to['name']); } }); } } }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Symfony\Component\HttpFoundation\Response */ public function render($request, Exception $e) { $e = FlattenException::create($e); $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false)); $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e)); return Response::create($decorated, $e->getStatusCode(), $e->getHeaders()); }
/** * Convert an exception to a response * * @param \Exception $exception * @return \Symfony\Component\HttpFoundation\Response */ public function handleException($exception) { if (!$exception instanceof FlattenException) { $exception = FlattenException::create($exception); } $handler = new BaseExceptionHandler($this->debug); $decorated = $this->decorate($handler->getContent($exception), $handler->getStylesheet($exception)); return new Response($decorated, $exception->getStatusCode(), $exception->getHeaders()); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ErrorException) { // This makes use of a Symfony error handler to make pretty traces. $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug')); $FlattenException = FlattenException::create($e); $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException); $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException); return response()->view('errors.500', ['error' => $e, 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500); } else { return parent::render($request, $e); } }
public function getContent(FlattenException $exception) { if ($exception->getStatusCode() == '500') { $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(), 'trace' => $exception->getTrace()]); } switch (true) { case 404 === $exception->getStatusCode(): if (null !== $this->translator) { $title = $this->translator->trans('Sorry, the page you are looking for could not be found.'); } else { $title = 'Sorry, the page you are looking for could not be found.'; } break; case 403 === $exception->getStatusCode(): if (null !== $this->translator) { $title = $this->translator->trans('Sorry, you do have access to the page you are looking for.'); } else { $title = 'Sorry, you do have access to the page you are looking for.'; } break; case 500 === $exception->getStatusCode(): if (null !== $this->translator) { $title = $this->translator->trans('Whoops, looks like something went wrong.'); } else { $title = 'Whoops, looks like something went wrong.'; } break; case 503 === $exception->getStatusCode(): if (null !== $this->translator) { $title = $this->translator->trans('Sorry, site is currently undergoing maintenance, come back soon.'); } else { $title = 'Sorry, site is currently undergoing maintenance, come back soon.'; } break; case isset(Response::$statusTexts[$exception->getStatusCode()]): $title = $exception->getStatusCode() . ' : ' . Response::$statusTexts[$exception->getStatusCode()]; break; default: if (null !== $this->translator) { $title = $this->translator->trans('Whoops, looks like something went wrong.'); } else { $title = 'Whoops, looks like something went wrong.'; } } $content = parent::getContent($exception); $start = strpos($content, '</h1>'); $content = '<div id="sf-resetcontent" class="sf-reset">' . '<h1><span>' . $title . '</span></h1>' . substr($content, $start + 5); return $content; }
/** * Renders the exception panel for the given token. * * @param string $token The profiler token * * @return Response A Response instance * * @throws NotFoundHttpException */ public function showAction($token) { if (null === $this->profiler) { throw new NotFoundHttpException('The profiler must be enabled.'); } $this->profiler->disable(); $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException(); $template = $this->getTemplate(); if (!$this->twig->getLoader()->exists($template)) { $handler = new ExceptionHandler(); return new Response($handler->getContent($exception), 200, array('Content-Type' => 'text/html')); } $code = $exception->getStatusCode(); return Response::create($this->twig->render($template, array('status_code' => $code, 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => null, 'currentContent' => '')), 200, array('Content-Type' => 'text/html'))->setCharset('UTF-8'); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } elseif ($e instanceof AuthorizationException) { $e = new HttpException(403, $e->getMessage()); } elseif ($e instanceof ValidationException && $e->getResponse()) { return $e->getResponse(); } $fe = FlattenException::create($e); $handler = new SymfonyExceptionHandler(env('APP_DEBUG', false)); $decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe)); $response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders()); $response->exception = $e; return $response; }
/** * Create a Symfony response for the given exception. * * @param \Exception $e * @return \Symfony\Component\HttpFoundation\Response */ protected function convertExceptionToResponse(Exception $e) { $e = FlattenException::create($e); $handler = new SymfonyExceptionHandler(config('app.debug')); $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e)); return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders()); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { $errorView = false; $errorEmail = false; switch (get_class($e)) { case "App\\Exceptions\\TorClearnet": $errorView = "errors.403_tor_clearnet"; break; case "Swift_TransportException": case "PDOException": $errorView = "errors.500_config"; $errorEmail = true; break; case "ErrorException": case "Symfony\\Component\\Debug\\Exception\\FatalThrowableError": $errorView = "errors.500"; $errorEmail = true; break; case "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException": return abort(400); case "Predis\\Connection\\ConnectionException": $errorView = "errors.500_predis"; $errorEmail = true; break; default: $errorView = false; break; } if (env('APP_DEBUG', false)) { $errorView = false; } $errorEmail = $errorEmail && env('MAIL_ADDR_ADMIN', false) && env('MAIL_ADMIN_SERVER_ERRORS', false); if ($errorEmail) { // This makes use of a Symfony error handler to make pretty traces. $SymfonyDisplayer = new SymfonyDisplayer(true); $FlattenException = isset($FlattenException) ? $FlattenException : FlattenException::create($e); $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException); $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException); $data = ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml]; Mail::send('emails.error', $data, function ($message) { $to = env('SITE_NAME', 'Infinity Next') . " Webaster"; $subject = env('SITE_NAME', 'Infinity Next') . " Error"; $subject .= " " . Request::url() ?: ""; $message->to(env('MAIL_ADDR_ADMIN', false), $to); $message->subject($subject); }); } if ($errorView) { // Duplicating logic in $errorEmail because output is completely // diffrent without app.debug enabled. I always want a stack trace // in my emails! $SymfonyDisplayer = new SymfonyDisplayer(config('app.debug')); $FlattenException = isset($FlattenException) ? $FlattenException : FlattenException::create($e); $SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException); $SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException); $response = response()->view($errorView, ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500); return $this->toIlluminateResponse($response, $e); } return parent::render($request, $e); }
protected function originalConvertExceptionToResponseWithDebugEnabled(Exception $exc) { // needed for emails and file logs, otherwise it will be useless $e = FlattenException::create($exc); $handler = new SymfonyExceptionHandler(true); $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e)); return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders()); }