Basically, this class removes all objects from the trace.
Author: Fabien Potencier (fabien@symfony.com)
コード例 #1
0
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if ($exception->getClass() == MailException::class) {
         return new Response($this->twig->render('CantigaCoreBundle:Exception:mail-exception.html.twig', array('message' => $exception->getMessage())), 501);
     }
     return parent::showAction($request, $exception, $logger);
 }
コード例 #2
0
 /**
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException(FlattenException $exception)
 {
     $errorPageUrl = $this->application->url($this->errorPageNamePrefix . $exception->getStatusCode());
     $request = Request::create($errorPageUrl, 'GET', ['exception' => $exception]);
     $response = $this->application->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     return $response;
 }
コード例 #3
0
ファイル: PageController.php プロジェクト: pixocode/noostache
 public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger)
 {
     $viewData = [];
     $viewData['status'] = $exception->getStatusCode();
     $viewData['message'] = $exception->getMessage();
     return $this->render('AppBundle:Exception:error.html.twig', $viewData);
 }
コード例 #4
0
 /**
  * Converts a {@see \Symfony\Component\Debug\Exception\FlattenException}
  * to a {@see \Dunglas\ApiBundle\JsonLd\Response}.
  *
  * @param FlattenException $exception
  *
  * @return Response
  */
 public function __invoke(FlattenException $exception)
 {
     $exceptionClass = $exception->getClass();
     if (is_a($exceptionClass, ExceptionInterface::class, true) || is_a($exceptionClass, InvalidArgumentException::class, true)) {
         $exception->setStatusCode(Response::HTTP_BAD_REQUEST);
     }
     return new Response($this->normalizer->normalize($exception, 'hydra-error'), $exception->getStatusCode(), $exception->getHeaders());
 }
コード例 #5
0
 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render((string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
コード例 #6
0
 /**
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *
  * @throws \Spryker\Yves\Application\Plugin\Exception\UndefinedExceptionHandlerException
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function dispatch(FlattenException $exception)
 {
     $statusCode = $exception->getStatusCode();
     if (isset($this->exceptionHandlers[$statusCode])) {
         return $this->exceptionHandlers[$statusCode]->handleException($exception);
     }
     throw new UndefinedExceptionHandlerException(sprintf('Undefined exception handler for status code "%d".', $statusCode));
 }
コード例 #7
0
 public function showAction(FlattenException $exception)
 {
     $statusCode = $exception->getStatusCode();
     if ($statusCode == 404) {
         $template = 'SurfnetStepupBundle:Exception:error404.html.twig';
     } else {
         $template = 'SurfnetStepupBundle:Exception:error.html.twig';
     }
     return $this->render($template, ['exception' => $exception, 'art' => Art::forFlattenException($exception), 'statusCode' => $statusCode, 'statusText' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '']);
 }
コード例 #8
0
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if ($exception->getStatusCode() == 404) {
         $uri = str_replace('/app_dev.php', '', $request->getRequestUri());
         $redirectUri = $this->get('iphp.redirectnotfound.observer_pool')->findRedirect($uri);
         if (!is_null($redirectUri)) {
             return new RedirectResponse($redirectUri, 301);
         }
     }
     return $this->get('twig.controller.exception')->showAction($request, $exception, $logger);
 }
コード例 #9
0
 /**
  * Converts an Exception to a Response.
  *
  * @param  Request          $request
  * @param  FlattenException $exception
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception)
 {
     if (is_subclass_of($exception->getClass(), 'Pagekit\\Kernel\\Exception\\HttpException')) {
         $title = $exception->getMessage();
     } else {
         $title = __('Whoops, looks like something went wrong.');
     }
     $content = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $response = App::view('system/error.php', compact('title', 'exception', 'content'));
     return App::response($response, $exception->getCode(), $exception->getHeaders());
 }
コード例 #10
0
 /**
  * Сериализует исключение и возвращает исключение.
  * 
  * @param Request $request Запрос
  * @param FlattenException $exception Исключение
  * @param DebugLoggerInterface $logger Лог
  * @param string $format Формат сериализации
  * @return Response
  */
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'json')
 {
     /** @var \FOS\RestBundle\View\ViewHandler $viewHandler */
     $viewHandler = $this->get('fos_rest.view_handler');
     // Если формат сериализации не поддерживается, то выбирается json
     if ($viewHandler->isFormatTemplating($format)) {
         $format = 'json';
     }
     $view = View::create()->setStatusCode($exception->getStatusCode())->setData(new ExceptionRepresentation($exception->getStatusCode(), $exception->getMessage(), null))->setFormat($format);
     return $viewHandler->handle($view);
 }
コード例 #11
0
 /**
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $status = $exception->getStatusCode();
     $message = $exception->getMessage();
     $previousUrl = $request->headers->get('referer');
     if ($request->getFormat($request->getAcceptableContentTypes()[0]) == 'json') {
         return new JsonResponse(['status' => $status, 'message' => $message]);
     } else {
         return $this->render('exception/404.html.twig', ['status' => $status, 'message' => $message, 'previousUrl' => $previousUrl]);
     }
 }
コード例 #12
0
 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     $response = ['error' => $code, 'message' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : ''];
     if ($showException) {
         $response['exception'] = $exception->toArray();
     }
     return new JsonResponse($response, $code);
 }
コード例 #13
0
 public function exceptionAction(Request $request, FlattenException $exception)
 {
     $status = $exception->getStatusCode();
     $message = $status && $status < 500 ? $exception->getMessage() : Translate::t("Sorry, there has been an internal error. The administrators have been notified and will fix this as soon as possible.");
     try {
         $reqDetails = $this->load($request);
         $pageDetails = $this->get("agit.page")->getPage("_exception");
         $response = $this->createResponse($pageDetails, $reqDetails, ["message" => $message]);
     } catch (Exception $e) {
         $response = $this->render("AgitPageBundle:Special:exception.html.twig", ["locale" => "en_GB", "message" => $message]);
     }
     $response->setStatusCode($status);
     $response->headers->set("X-Frame-Options", "SAMEORIGIN");
     return $response;
 }
コード例 #14
0
 public function handleKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->container->get('kernel')->getEnvironment() !== 'dev') {
         $exception = FlattenException::create($event->getException());
         // First, log the exception to the standard error logs.
         $this->container->get('logger')->error(' In File ' . $exception->getFile() . ', on line ' . $exception->getLine() . ': ' . $exception->getMessage());
         // Determine what the HTTP status code should be.
         if ($event->getException() instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
             $httpStatusCode = $event->getException()->getStatusCode();
         } else {
             $httpStatusCode = $exception->getCode();
             if ($exception->getCode() < 100 || $exception->getCode() >= 600) {
                 $httpStatusCode = 500;
             }
         }
         $parameters = ['status_code' => $httpStatusCode, 'status_text' => $exception->getMessage(), 'exception' => $exception];
         if (in_array('application/json', $event->getRequest()->getAcceptableContentTypes())) {
             $errorContent = $this->container->get('templating')->render(':default:exception.json.twig', $parameters);
         } else {
             $errorContent = $this->container->get('templating')->render(':default:error.html.twig', $parameters);
         }
         $response = new Response($errorContent, $httpStatusCode);
         $response->setProtocolVersion('1.1');
         $event->setResponse($response);
     }
 }
コード例 #15
0
 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']);
                 }
             });
         }
     }
 }
 public function createApplication()
 {
     $app = new ApplicationTest();
     $app['route_class'] = 'Euskadi31\\Silex\\Controller\\RouteTest';
     $app['debug'] = true;
     //unset($app['exception_handler']);
     $app->mount('/', new AuthorizeControllerProvider());
     $app->error(function (Exception $exception, $code) use($app) {
         $e = FlattenException::create($exception);
         $headers = [];
         if ($exception instanceof HttpExceptionInterface) {
             $headers = $exception->getHeaders();
             $code = $exception->getStatusCode();
         } else {
             $code = $exception->getCode();
         }
         if ($code < 100 || $code >= 600) {
             $code = 500;
         }
         $error = ['error' => ['message' => $exception->getMessage(), 'type' => join('', array_slice(explode('\\', get_class($exception)), -1)), 'code' => $code]];
         if ($this->app['debug']) {
             $error['error']['exception'] = $e->toArray();
         }
         return new Response($app->json($error, $code, $headers));
     });
     return $app;
 }
コード例 #17
0
 /**
  * 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());
 }
コード例 #18
0
ファイル: ExceptionListener.php プロジェクト: voxsim/minima
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $flattenException = FlattenException::create($exception);
     $msg = 'Something went wrong! (' . $flattenException->getMessage() . ')';
     $event->setResponse(new Response($msg, $flattenException->getStatusCode()));
 }
コード例 #19
0
ファイル: ExceptionAction.php プロジェクト: api-platform/core
 /**
  * Converts a an exception to a JSON response.
  *
  * @param FlattenException $exception
  * @param Request          $request
  *
  * @return Response
  */
 public function __invoke(FlattenException $exception, Request $request) : Response
 {
     $exceptionClass = $exception->getClass();
     foreach ($this->exceptionToStatus as $class => $status) {
         if (is_a($exceptionClass, $class, true)) {
             $exception->setStatusCode($status);
             break;
         }
     }
     $headers = $exception->getHeaders();
     $format = ErrorFormatGuesser::guessErrorFormat($request, $this->errorFormats);
     $headers['Content-Type'] = sprintf('%s; charset=utf-8', $format['value'][0]);
     $headers['X-Content-Type-Options'] = 'nosniff';
     $headers['X-Frame-Options'] = 'deny';
     return new Response($this->serializer->serialize($exception, $format['key']), $exception->getStatusCode(), $headers);
 }
コード例 #20
0
 /**
  * Clones the request for the exception.
  *
  * @param \Exception $exception
  * @param  Request   $request
  * @return Request   $request
  */
 protected function duplicateRequest(\Exception $exception, Request $request)
 {
     $attributes = ['_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger];
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     return $request;
 }
コード例 #21
0
 private function saveDebugInformation(\Exception $ex = null)
 {
     if (!$this->input->hasOption('jms-job-id') || null === ($jobId = $this->input->getOption('jms-job-id'))) {
         return;
     }
     $this->getConnection()->executeUpdate("UPDATE jms_jobs SET stackTrace = :trace, memoryUsage = :memoryUsage, memoryUsageReal = :memoryUsageReal WHERE id = :id", array('id' => $jobId, 'memoryUsage' => memory_get_peak_usage(), 'memoryUsageReal' => memory_get_peak_usage(true), 'trace' => serialize($ex ? class_exists(FlattenException::class) ? FlattenException::create($ex) : LegacyFlattenException::create($ex) : null)), array('id' => \PDO::PARAM_INT, 'memoryUsage' => \PDO::PARAM_INT, 'memoryUsageReal' => \PDO::PARAM_INT, 'trace' => \PDO::PARAM_LOB));
 }
コード例 #22
0
ファイル: ExceptionHandler.php プロジェクト: pagekit/pagekit
 /**
  * {@inheritdoc}
  */
 public function createResponse($exception)
 {
     if ($exception instanceof HttpException) {
         $exception = FlattenException::create($exception, $exception->getCode());
     }
     return parent::createResponse($exception);
 }
コード例 #23
0
ファイル: Handler.php プロジェクト: inklabs/kommerce-laravel
 protected function convertExceptionToResponse(Exception $e)
 {
     $e = FlattenException::create($e);
     $handler = new KommerceExceptionHandler(config('app.debug'));
     $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));
     return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders());
 }
コード例 #24
0
ファイル: Mailer.php プロジェクト: ehough/emailerrors-bundle
 public function sendMail(\Exception $exception, Request $request, array $context, $needToFlush)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     if (!$this->_hasInitialized) {
         $this->_initialize();
     }
     $params = array('exception' => $exception, 'request' => $request, 'context' => $context, 'status_text' => Response::$statusTexts[$exception->getStatusCode()]);
     $preMailEvent = new GenericEvent($params, array('shouldSend' => true));
     $this->_eventDispatcher->dispatch('ehough.bundle.emailErrors.preMail', $preMailEvent);
     if (!$preMailEvent->getArgument('shouldSend')) {
         //mail was cancelled
         return;
     }
     $body = $this->_templatingEngine->render('EhoughEmailErrorsBundle::mail.html.twig', $params);
     $subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
     if (function_exists('mb_substr')) {
         $subject = mb_substr($subject, 0, 255);
     } else {
         $subject = substr($subject, 0, 255);
     }
     $mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->_fromAddress)->setTo($this->_toAddress)->setContentType('text/html')->setBody($body);
     $this->_mailer->send($mail);
     if ($needToFlush) {
         $this->_flushEmailer();
     }
 }
コード例 #25
0
ファイル: ExceptionListener.php プロジェクト: ccq18/EduSoho
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     } catch (\Exception $e) {
         $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
         $wrapper = $e;
         while ($prev = $wrapper->getPrevious()) {
             if ($exception === ($wrapper = $prev)) {
                 throw $e;
             }
         }
         $prev = new \ReflectionProperty('Exception', 'previous');
         $prev->setAccessible(true);
         $prev->setValue($wrapper, $exception);
         throw $e;
     }
     $event->setResponse($response);
 }
コード例 #26
0
ファイル: Handler.php プロジェクト: RustyGamer/infinity-next
 /**
  * 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);
     }
 }
コード例 #27
0
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
         // set handling to false otherwise it wont be able to handle further more
         $handling = false;
         // re-throw the exception from within HttpKernel as this is a catch-all
         return;
     }
     $event->setResponse($response);
     $handling = false;
 }
コード例 #28
0
 public function getTrace($previewLines = 3)
 {
     $trace = parent::getTrace();
     if (!is_array($trace)) {
         return;
     }
     $trace[1]['file'] = $this->getFile();
     $trace[1]['line'] = $this->getLine();
     if ($previewLines === false) {
         return $trace;
     }
     foreach ($trace as &$item) {
         if (!$item['file'] || !$item['line']) {
             continue;
         }
         $item['file_preview'] = [];
         $fileContents = file_get_contents($item['file']);
         $fileContents = explode("\n", $fileContents);
         $firstLine = max($item['line'] - $previewLines, 1);
         $lastLine = min($item['line'] + $previewLines, count($fileContents));
         for ($line = $firstLine; $line <= $lastLine; $line++) {
             $item['file_preview'][$line] = $fileContents[$line - 1];
         }
     }
     return $trace;
 }
コード例 #29
0
 protected function handleWithSymfony(Exception $exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new ExceptionHandler($this->debug);
     return Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders());
 }
コード例 #30
0
ファイル: ExceptionController.php プロジェクト: flint/brick
 public function __invoke(Request $request, FlattenException $exception, $format)
 {
     $statusCode = $exception->getStatusCode();
     try {
         $template = $this->twig->resolveTemplate(['Exception/error' . $statusCode . '.' . $format . '.twig', 'Exception/error.' . $format . '.twig', 'Exception/error.html.twig']);
     } catch (\Twig_Error_Loader $e) {
         $request->setRequestFormat('html');
         $content = (new ExceptionHandler(false))->getHtml($exception);
         return new Response($content, $exception->getStatusCode(), $exception->getHeaders());
     }
     // We cannot find a template that matches the precise format so we will default
     // to html as previously in the ExceptionHandler
     if (substr($template->getTemplateName(), -9) == 'html.twig') {
         $request->setRequestFormat('html');
     }
     $variables = ['exception' => $exception, 'status_code' => $statusCode, 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : ''];
     return new Response($template->render($variables), $statusCode);
 }