Piwik\Tracker\Response::outputException PHP Method

outputException() public method

Echos an error message & other information, then exits.
public outputException ( Piwik\Tracker $tracker, Exception $e, integer $statusCode )
$tracker Piwik\Tracker
$e Exception
$statusCode integer eg 500
    public function outputException(Tracker $tracker, Exception $e, $statusCode)
    {
        Common::sendResponseCode($statusCode);
        $this->logExceptionToErrorLog($e);
        if ($tracker->isDebugModeEnabled()) {
            Common::sendHeader('Content-Type: text/html; charset=utf-8');
            $trailer = '<span style="color: #888888">Backtrace:<br /><pre>' . $e->getTraceAsString() . '</pre></span>';
            $headerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutHeader.tpl');
            $footerPage = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/Morpheus/templates/simpleLayoutFooter.tpl');
            $headerPage = str_replace('{$HTML_TITLE}', 'Piwik &rsaquo; Error', $headerPage);
            echo $headerPage . '<p>' . $this->getMessageFromException($e) . '</p>' . $trailer . $footerPage;
        } else {
            $this->outputApiResponse($tracker);
        }
    }

Usage Example

Example #1
0
 public function onException(Tracker $tracker, RequestSet $requestSet, Exception $e)
 {
     Common::printDebug("Exception: " . $e->getMessage());
     $statusCode = 500;
     if ($e instanceof UnexpectedWebsiteFoundException) {
         $statusCode = 400;
     } elseif ($e instanceof InvalidRequestParameterException) {
         $statusCode = 400;
     }
     $this->response->outputException($tracker, $e, $statusCode);
     $this->redirectIfNeeded($requestSet);
 }