Example #1
0
    protected function onError(Exception $e)
    {
        $errorMessage = '<p>An error occurred during execution of the application.</p>';
        if ($this->debugEnabled) {
            $message = '<strong>' . get_class($e) . '</strong>: ' . htmlentities($e->getMessage(), ENT_QUOTES, 'UTF-8');
            $stackTrace = htmlentities($e->getTraceAsString(), ENT_QUOTES, 'UTF-8');
            $errorMessage = <<<ERROR
\t\t<p>{$message}</p>
\t\t<pre>{$stackTrace}</pre>
ERROR;
        }
        $html = <<<HTML
<!doctype html>
<html>
\t<head>
\t\t<title>An error occurred</title>
\t\t<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
\t</head>

\t<body>
\t\t<h1>An error occurred</h1>
{$errorMessage}
\t</body>
</html>
HTML;
        $statusCode = $e instanceof HttpException ? $e->getStatusCode() : 500;
        $this->response->clear()->setStatus($statusCode)->write($html)->flush();
    }