/** * Render an HTML error page from an exception. * * @param Exception $exception * @param Mad_Controller_Request_Http $request * @param Mad_Controller_Response_Http $response */ public function render($exception, $request, $response) { // If there is anything leftover in the output buffer, such // as interrupted template rendering, destroy it. while (ob_get_level()) { ob_get_clean(); } // title if ($exception instanceof Mad_Support_Exception) { $title = $exception->getTitle(); } else { $title = get_class($exception); } // message if (!strlen($message = $exception->getMessage())) { $message = "<no message>"; } // assignments $this->_view->title = $title; $this->_view->message = $message; $this->_view->exception = $exception; $this->_view->trace = $this->formatTrace($exception); $this->_view->request = $request; $this->_view->response = $response; $this->_view->extraction = $this->extractSource($exception); // render the error page contents $this->_view->contents = $this->_view->render('diagnostics'); // render the error layout $html = $this->_view->render('layout'); return $html; }
public function handleRequestException(AphrontRequest $request, Exception $ex) { $viewer = $this->getViewer($request); if (!$viewer->isLoggedIn()) { // If the user isn't logged in, just give them a login form. This is // probably a generally more useful response than a policy dialog that // they have to click through to get a login form. // // Possibly we should add a header here like "you need to login to see // the thing you are trying to look at". $auth_app_class = 'PhabricatorAuthApplication'; $auth_app = PhabricatorApplication::getByClass($auth_app_class); return id(new PhabricatorAuthStartController())->setRequest($request)->setCurrentApplication($auth_app)->handleRequest($request); } $content = array(phutil_tag('div', array('class' => 'aphront-policy-rejection'), $ex->getRejection())); $list = null; if ($ex->getCapabilityName()) { $list = $ex->getMoreInfo(); foreach ($list as $key => $item) { $list[$key] = $item; } $content[] = phutil_tag('div', array('class' => 'aphront-capability-details'), pht('Users with the "%s" capability:', $ex->getCapabilityName())); } $dialog = id(new AphrontDialogView())->setTitle($ex->getTitle())->setClass('aphront-access-dialog')->setUser($viewer)->appendChild($content); if ($list) { $dialog->appendList($list); } if ($request->isAjax()) { $dialog->addCancelButton('/', pht('Close')); } else { $dialog->addCancelButton('/', pht('OK')); } return $dialog; }
/** * Schreibt die Exception in eine Log-Datei * * @param Exception $e Exceptionklasse */ public static function logException($e, $title = null, $comment = null) { date_default_timezone_set("Europe/Zurich"); $time = date("Y-m-d H:i"); if (empty($title)) { $title = $e->getTitle(); } $rpcl_arr = array("\t" => " ", "\n" => " ", "\r" => " ", "\\xOB" => " "); $file = $e->getFile(); $code = $e->getCode(); $msg = strtr($e->getMessage(), $rpcl_arr); $line = $e->getLine(); $trace = strtr($e->getTraceAsString(), $rpcl_arr); if (!empty($comment)) { $comment = strtr($comment, $rpcl_arr); } if (key_exists('HTTP_POST_VARS', $GLOBALS)) { $post = strtr(print_r($GLOBALS['HTTP_POST_VARS'], 1), $rpcl_arr); } else { $post = "POST_VARS ARE NOT AVAILABLE"; } if (key_exists('HTTP_GET_VARS', $GLOBALS)) { $get = strtr(print_r($GLOBALS['HTTP_GET_VARS'], 1), $rpcl_arr); } else { $get = "GET_VARS ARE NOT AVAILABLE"; } /* Log schreiben */ $fh = fopen(ADMIN_DIR . "log/.exception.log", "a"); $log_line = "#LOG-ENTRY\nTITLE: {$title}\nCODE: {$code}\nTIME: {$time}\nFILE: {$file}\nLINE: {$line}\nMESSAGE: {$msg}\n" . "TRACE: {$trace}\nPOST: {$post}\nGET: {$get}\nCOMMENT: {$comment}\n#END\n\n"; fputs($fh, $log_line); fclose($fh); }