public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html') { $statusCode = $exception->getStatusCode(); $statusText = $exception->getMessage(); $response = $this->render('GitonomyWebsiteBundle:Error:error.html.twig', array('status_code' => $statusCode, 'status_text' => $statusText)); $response->setStatusCode($statusCode); $response->headers->replace($exception->getHeaders()); return $response; }
/** * Converts an Exception to a Response. * * @param Request $request The request * @param FlattenException $exception A FlattenException instance * @param DebugLoggerInterface $logger A DebugLoggerInterface instance * * @param string $_format * @return JsonResponse */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html') { $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); $wrapper = new ExceptionWrapper(); $wrapper->setCode($exception->getCode()); $wrapper->setMessage($exception->getMessage()); $wrapper->setStatusCode($exception->getStatusCode()); $wrapper->setTrace($this->debug ? $exception->getTrace() : array()); return $wrapper->getResponse(); }
/** * @param Request $request * @param FlattenException $exception * @param DebugLoggerInterface $logger * @return \GoIntegro\Hateoas\Http\JsonResponse */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = NULL) { $error = new ErrorObject(); $error->status = $exception->getStatusCode(); $error->title = $exception->getMessage(); $error->code = $exception->getCode(); $serializer = new ErrorSerializer($error); if (500 == $error->status && NULL != $logger) { $logger->error(sprintf(self::ERROR_LOG_MESSAGE_PATTERN, $error->title, $exception->getFile(), $exception->getLine(), $error->id)); } return $this->createNoCacheResponse($serializer->serialize(), $error->status, $exception->getHeaders()); }
/** * @param Request $request * @param FlattenException $exception * @param DebugLoggerInterface $logger * @return \Symfony\Component\HttpFoundation\Response */ public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { /** @var Translator $translator */ $translator = $this->get('translator'); $message = $translator->trans('error.messages.generic'); // check if the error is whitelisted to overrule the message if (in_array($exception->getClass(), $this->container->getParameter('sumo_coders_framework_error.show_messages_for'))) { $message = $exception->getMessage(); } // translate page not found messages if ('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException' == $exception->getClass()) { $message = $translator->trans('error.messages.noRouteFound'); } return $this->render('::error.html.twig', array('status_code' => $exception->getStatusCode(), 'status_text' => $message)); }
/** * 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) { $opts = array(); $params = array(); //------------------------------ $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(); $message = $exception->getMessage(); $arrAlertMessage = $this->getAlertMessage($message); $attrs = $request->attributes->all(); if (isset($attrs['_route'])) { $route = $attrs['_route']; } else { $route = 'indefinite'; } if (isset($this->app["my.opts"]) && isset($this->app["my.opts"])) { $opts = $this->app["my.opts"]; $params = $this->app["my.params"]; } return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('route' => $route, 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'parameters' => $this->ArrData2View($opts + $params)))); }
/** * Extract the exception message * * @param FlattenException $exception A FlattenException instance * * @return string Message */ protected function getExceptionMessage($exception) { $exceptionClass = $exception->getClass(); $exceptionMap = $this->container->getParameter('fos_rest.exception.messages'); return !empty($exceptionMap[$exceptionClass]) || $this->container->get('kernel')->isDebug() ? $exception->getMessage() : ''; }
/** * Retrieve a textual description of the given Exception, or FlattenException (as passed by Symfony HttpKernel). * * @param \Symfony\Component\HttpKernel\Exception\FlattenException|\Exception $exception * @param string|null $adminName * @param string|null $adminEmail * @param string $heading * @param null $stackTraceHeading * * @return string */ public static function exception($exception, $adminName = null, $adminEmail = null, $heading = null, $stackTraceHeading = null) { // Generate the error message. ob_start(); echo $heading ?: '<h1>Error</h1>', PHP_EOL; echo '<p><strong>', $exception->getMessage(), '</strong></p>', PHP_EOL; echo '<p>Error occurred at ', date('Y-m-d H:i:s'), ', code: ', $exception->getCode(), ', ', TypeUtilities::describe($exception), '</p>', PHP_EOL; echo '<p>Please contact your system administrator for assistance.</p>' . PHP_EOL; if (!empty($adminName) || !empty($adminEmail)) { echo '<ul>', PHP_EOL; if (!empty($adminName)) { echo '<li>Name: ', $adminName, '</li>', PHP_EOL; } if (!empty($adminEmail)) { echo '<li>Email Address: ', $adminEmail, '</li>', PHP_EOL; } echo '</ul>', PHP_EOL; } echo '<hr/>', PHP_EOL; echo $stackTraceHeading ?: '<h2>Stack Trace</h2>', PHP_EOL; echo '<ol>', PHP_EOL; foreach (array_reverse($exception->getTrace()) as $traceItem) { $file = isset($traceItem['file']) ? $traceItem['file'] : ''; $line = isset($traceItem['line']) ? sprintf('(%s)', $traceItem['line']) : ''; $function = isset($traceItem['function']) ? isset($traceItem['class']) && !empty($traceItem['class']) ? sprintf('%s->%s', $traceItem['class'], $traceItem['function']) : $traceItem['function'] : ''; echo '<li>', $file, $line, ': ', $function, '()</li>', PHP_EOL; } echo '</ol>'; return ob_get_clean(); }
/** * Gets the HTML content associated with the given exception. * * @param FlattenException $exception A FlattenException instance * * @return string The content as a string */ public function getContent(FlattenException $exception) { $title = ''; switch ($exception->getStatusCode()) { case 404: $title = 'Sorry, the page you are looking for could not be found.'; break; default: $title = 'Whoops, looks like something went wrong.'; } $content = ''; if ($this->debug) { try { $message = nl2br($exception->getMessage()); $class = $this->abbrClass($exception->getClass()); $count = count($exception->getAllPrevious()); $content = ''; foreach ($exception->toArray() as $position => $e) { $ind = $count - $position + 1; $total = $count + 1; $class = $this->abbrClass($e['class']); $message = nl2br($e['message']); $content .= sprintf(<<<EOF <div class="block_exception clear_fix"> <h2><span>%d/%d</span> %s: %s</h2> </div> <div class="block"> <ol class="traces list_exception"> EOF , $ind, $total, $class, $message); foreach ($e['trace'] as $i => $trace) { $content .= ' <li>'; if ($trace['function']) { $content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args'])); } if (isset($trace['file']) && isset($trace['line'])) { if ($linkFormat = ini_get('xdebug.file_link_format')) { $link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat); $content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']); } else { $content .= sprintf(' in %s line %s', $trace['file'], $trace['line']); } } $content .= "</li>\n"; } $content .= " </ol>\n</div>\n"; } } catch (\Exception $e) { // something nasty happened and we cannot throw an exception anymore if ($this->debug) { $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage()); } else { $title = 'Whoops, looks like something went wrong.'; } } } return <<<EOF <div id="sf-resetcontent" class="sf-reset"> <h1>{$title}</h1> {$content} </div> EOF; }
public function exceptionAction(FlattenException $exception) { $msg = 'Something went wrong! (' . $exception->getMessage() . ')'; return new Response($msg, $exception->getStatusCode()); }