private static function getErrorResponse(Exception $ex) { $debugTrace = $ex->getTraceAsString(); $message = $ex->getMessage(); if (!method_exists($ex, 'isHtmlMessage') || !$ex->isHtmlMessage()) { $message = Common::sanitizeInputValue($message); } $logo = new CustomLogo(); $logoHeaderUrl = false; $logoFaviconUrl = false; try { $logoHeaderUrl = $logo->getHeaderLogoUrl(); $logoFaviconUrl = $logo->getPathUserFavicon(); } catch (Exception $ex) { Log::debug($ex); } $result = Piwik_GetErrorMessagePage($message, $debugTrace, true, true, $logoHeaderUrl, $logoFaviconUrl); /** * Triggered before a Piwik error page is displayed to the user. * * This event can be used to modify the content of the error page that is displayed when * an exception is caught. * * @param string &$result The HTML of the error page. * @param Exception $ex The Exception displayed in the error page. */ Piwik::postEvent('FrontController.modifyErrorPage', array(&$result, $ex)); return $result; }
private static function getErrorResponse(Exception $ex) { $debugTrace = $ex->getTraceAsString(); $message = $ex->getMessage(); $isHtmlMessage = method_exists($ex, 'isHtmlMessage') && $ex->isHtmlMessage(); if (!$isHtmlMessage && Request::isApiRequest($_GET)) { $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST)); $response = new ResponseBuilder($outputFormat); return $response->getResponseException($ex); } elseif (!$isHtmlMessage) { $message = Common::sanitizeInputValue($message); } $logo = new CustomLogo(); $logoHeaderUrl = false; $logoFaviconUrl = false; try { $logoHeaderUrl = $logo->getHeaderLogoUrl(); $logoFaviconUrl = $logo->getPathUserFavicon(); } catch (Exception $ex) { try { Log::debug($ex); } catch (\Exception $otherEx) { // DI container may not be setup at this point } } $result = Piwik_GetErrorMessagePage($message, $debugTrace, true, true, $logoHeaderUrl, $logoFaviconUrl); try { /** * Triggered before a Piwik error page is displayed to the user. * * This event can be used to modify the content of the error page that is displayed when * an exception is caught. * * @param string &$result The HTML of the error page. * @param Exception $ex The Exception displayed in the error page. */ Piwik::postEvent('FrontController.modifyErrorPage', array(&$result, $ex)); } catch (ContainerDoesNotExistException $ex) { // this can happen when an error occurs before the Piwik environment is created } return $result; }
<li><a rel="noreferrer" target="_blank" href="http://piwik.org/docs/">Piwik Documentation</a></li> <li><a rel="noreferrer" target="_blank" href="http://forum.piwik.org/">Piwik Forums</a></li> <li><a rel="noreferrer" target="_blank" href="http://demo.piwik.org">Piwik Online Demo</a></li> </ul>'; } if ($optionalLinkBack) { $optionalLinkBack = '<a href="javascript:window.history.back();">Go Back</a>'; } $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl'); $headerPage = str_replace('%logoUrl%', $logoUrl, $headerPage); $headerPage = str_replace('%faviconUrl%', $faviconUrl, $headerPage); $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl'); $headerPage = str_replace('{$HTML_TITLE}', PAGE_TITLE_WHEN_ERROR, $headerPage); $content = '<h2>' . $message . '</h2> <p>' . $optionalLinkBack . ' | <a href="index.php">Go to Piwik</a> | <a href="index.php?module=Login">Login</a>' . '</p>' . ' ' . (Piwik_ShouldPrintBackTraceWithMessage() ? $optionalTrace : '') . ' ' . $optionalLinks; $message = str_replace(array("<br />", "<br>", "<br/>", "</p>"), "\n", $message); $message = str_replace("\t", "", $message); $message = strip_tags($message); if (!$isCli) { $message = $headerPage . $content . $footerPage; } $message .= "\n"; error_log(sprintf("Error in Piwik: %s", str_replace("\n", " ", $message))); return $message; } } if (!empty($piwik_errorMessage)) { echo Piwik_GetErrorMessagePage($piwik_errorMessage, false, true); exit(1); }