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); }
/** * 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()); }
/** * 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()); }
/** * 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); }
/** * Converts an Exception to a Response. * * @param Request $request * @param FlattenException $exception * @param DebugLoggerInterface $logger * @param string $_format * @throws \InvalidArgumentException * @return Response */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html') { $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); switch ($exception->getClass()) { case 'Pagekit\\Component\\Session\\Csrf\\Exception\\BadTokenException': $title = __('Invalid CSRF token.'); break; case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException': $title = __('Sorry, the page you are looking for could not be found.'); break; case 'Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException': $title = $exception->getMessage(); break; default: $title = __('Whoops, looks like something went wrong.'); } $response = $this['view']->render('extension://system/theme/templates/error.razr', compact('title', 'exception', 'currentContent')); return $this['response']->create($response, $exception->getStatusCode(), $exception->getHeaders()); }
/** * {@inheritdoc} */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { $class = $exception->getClass(); //ignore authentication exceptions if (strpos($class, 'Authentication') === false) { $env = $this->factory->getEnvironment(); $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); $layout = $env == 'prod' ? 'Error' : 'Exception'; $code = $exception->getStatusCode(); if ($code === 0) { //thrown exception that didn't set a code $code = 500; } // Special handling for oauth and api urls if (strpos($request->getUri(), '/oauth') !== false && strpos($request->getUri(), 'authorize') === false || strpos($request->getUri(), '/api') !== false) { $dataArray = array('error' => array('message' => $exception->getMessage(), 'code' => $code)); if ($env == 'dev') { $dataArray['trace'] = $exception->getTrace(); } return new JsonResponse($dataArray, 200); } if ($request->get('prod')) { $layout = 'Error'; } $anonymous = $this->factory->getSecurity()->isAnonymous(); $baseTemplate = 'MauticCoreBundle:Default:slim.html.php'; if ($anonymous) { if ($templatePage = $this->factory->getTheme()->getErrorPageTemplate($code)) { $baseTemplate = $templatePage; } } $template = "MauticCoreBundle:{$layout}:{$code}.html.php"; $templating = $this->factory->getTemplating(); if (!$templating->exists($template)) { $template = "MauticCoreBundle:{$layout}:base.html.php"; } $statusText = isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : ''; $url = $request->getRequestUri(); $urlParts = parse_url($url); return $this->delegateView(array('viewParameters' => array('baseTemplate' => $baseTemplate, 'status_code' => $code, 'status_text' => $statusText, 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'isPublicPage' => $anonymous), 'contentTemplate' => $template, 'passthroughVars' => array('error' => array('code' => $code, 'text' => $statusText, 'exception' => $env == 'dev' ? $exception->getMessage() : '', 'trace' => $env == 'dev' ? $exception->getTrace() : ''), 'route' => $urlParts['path']))); } }
/** * Extract the exception message * * @param HttpFlattenException|DebugFlattenException $exception A HttpFlattenException|DebugFlattenException instance * @param array $exceptionMap * * @return string Message */ protected function isSubclassOf($exception, $exceptionMap) { $exceptionClass = $exception->getClass(); $reflectionExceptionClass = new \ReflectionClass($exceptionClass); try { foreach ($exceptionMap as $exceptionMapClass => $value) { if ($value && ($exceptionClass === $exceptionMapClass || $reflectionExceptionClass->isSubclassOf($exceptionMapClass))) { return $value; } } } catch (\ReflectionException $re) { return "FOSUserBundle: Invalid class in fos_res.exception.messages: " . $re->getMessage(); } return false; }
/** * This method is a temporary port of _drupal_decode_exception(). * * @todo This should get refactored. FlattenException could use some * improvement as well. * * @param \Symfony\Component\Debug\Exception\FlattenException $exception * The flattened exception. * * @return array * An array of string-substitution tokens for formatting a message about the * exception. */ protected function decodeException(FlattenException $exception) { $message = $exception->getMessage(); $backtrace = $exception->getTrace(); // This value is missing from the stack for some reason in the // FlattenException version of the backtrace. $backtrace[0]['line'] = $exception->getLine(); // For database errors, we try to return the initial caller, // skipping internal functions of the database layer. if (strpos($exception->getClass(), 'DatabaseExceptionWrapper') !== FALSE) { // A DatabaseExceptionWrapper exception is actually just a courier for // the original PDOException. It's the stack trace from that exception // that we care about. $backtrace = $exception->getPrevious()->getTrace(); $backtrace[0]['line'] = $exception->getLine(); // The first element in the stack is the call, the second element gives us the caller. // We skip calls that occurred in one of the classes of the database layer // or in one of its global functions. $db_functions = array('db_query', 'db_query_range'); while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (strpos($caller['namespace'], 'Drupal\\Core\\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions)) { // We remove that call. array_shift($backtrace); } } $caller = Error::getLastCaller($backtrace); return array('%type' => $exception->getClass(), '!message' => String::checkPlain($message), '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => WATCHDOG_ERROR); }
/** * Extracts the exception message. * * @param HttpFlattenException|DebugFlattenException $exception * @param array $exceptionMap * * @return int|false */ protected function isSubclassOf($exception, $exceptionMap) { $exceptionClass = $exception->getClass(); foreach ($exceptionMap as $exceptionMapClass => $value) { if ($value && ($exceptionClass === $exceptionMapClass || is_subclass_of($exceptionClass, $exceptionMapClass))) { return $value; } } return false; }
/** * @param FlattenException $exception * @return string */ public static function forFlattenException(FlattenException $exception) { return self::calculateArt($exception->getClass(), $exception->getMessage()); }