2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
class ErrorController extends Zend_Controller_Action
|
|
|
|
{
|
2015-03-20 22:20:34 +01:00
|
|
|
public function init()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2022-03-14 11:15:04 +01:00
|
|
|
// The default layout includes the Dashboard header, which may contain private information.
|
|
|
|
// We cannot show that.
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->view->layout()->disableLayout();
|
|
|
|
$this->setupCSS();
|
2015-11-19 17:08:35 +01:00
|
|
|
|
|
|
|
// TODO: set Help button URL based on whether or not user is logged in
|
|
|
|
try {
|
|
|
|
$service_user = new Application_Service_UserService();
|
|
|
|
$service_user->getCurrentUser();
|
2022-07-07 23:27:28 +02:00
|
|
|
$this->view->helpUrl = Config::getBasePath() . 'dashboard/help';
|
2015-11-19 17:08:35 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->view->helpUrl = HELP_URL;
|
|
|
|
}
|
2015-03-20 22:20:34 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public function errorAction()
|
|
|
|
{
|
2010-12-07 20:19:27 +01:00
|
|
|
$errors = $this->_getParam('error_handler');
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
if ($errors) {
|
|
|
|
// log error message and stack trace
|
|
|
|
Logging::error($errors->exception->getMessage());
|
|
|
|
Logging::error($errors->exception->getTraceAsString());
|
|
|
|
|
|
|
|
switch ($errors->type) {
|
2021-10-11 16:10:47 +02:00
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
|
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->error404Action();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
break;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->error400Action();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
break;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
default:
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->error500Action();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-14 11:15:04 +01:00
|
|
|
// $exceptions = $this->_getAllParams();
|
|
|
|
// Logging::error($exceptions);
|
2015-06-16 20:58:27 +02:00
|
|
|
$this->error404Action();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
return;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
// Log exception, if logger available
|
2015-01-19 19:41:23 +01:00
|
|
|
/* No idea why this doesn't work or why it was implemented like this. Disabling it -- Albert
|
2013-05-28 23:45:09 +02:00
|
|
|
if (($log = $this->getLog())) {
|
2010-12-07 20:19:27 +01:00
|
|
|
$log->crit($this->view->message, $errors->exception);
|
2015-01-19 19:41:23 +01:00
|
|
|
}*/
|
2022-03-14 11:15:04 +01:00
|
|
|
// Logging that actually works: -- Albert
|
2021-10-11 16:10:47 +02:00
|
|
|
Logging::error($this->view->message . ': ' . $errors->exception);
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
// conditionally display exceptions
|
|
|
|
if ($this->getInvokeArg('displayExceptions') == true) {
|
|
|
|
$this->view->exception = $errors->exception;
|
|
|
|
}
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->view->request = $errors->request;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
private function setupCSS()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2022-09-19 11:58:31 +02:00
|
|
|
$this->view->headLink()->appendStylesheet(Assets::url('css/styles.css'));
|
2015-03-20 22:20:34 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public function getLog()
|
|
|
|
{
|
2010-12-07 20:19:27 +01:00
|
|
|
$bootstrap = $this->getInvokeArg('bootstrap');
|
|
|
|
if (!$bootstrap->hasPluginResource('Log')) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $bootstrap->getResource('Log');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* 404 error - route or controller.
|
2015-03-20 22:20:34 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function error404Action()
|
|
|
|
{
|
2015-06-16 20:58:27 +02:00
|
|
|
$this->_helper->viewRenderer('error');
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->getResponse()->setHttpResponseCode(404);
|
|
|
|
$this->view->message = _('Page not found.');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2015-03-20 22:20:34 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* 400 error - no such action.
|
2015-03-20 22:20:34 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function error400Action()
|
|
|
|
{
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->_helper->viewRenderer('error-400');
|
|
|
|
$this->getResponse()->setHttpResponseCode(400);
|
|
|
|
$this->view->message = _('The requested action is not supported.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* 403 error - permission denied.
|
2015-03-20 22:20:34 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function error403Action()
|
|
|
|
{
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->_helper->viewRenderer('error-403');
|
|
|
|
$this->getResponse()->setHttpResponseCode(403);
|
|
|
|
$this->view->message = _('You do not have permission to access this resource.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* 500 error - internal server error.
|
2015-03-20 22:20:34 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public function error500Action()
|
|
|
|
{
|
2015-03-20 22:20:34 +01:00
|
|
|
$this->_helper->viewRenderer('error-500');
|
|
|
|
|
|
|
|
$this->getResponse()->setHttpResponseCode(500);
|
|
|
|
$this->view->message = _('An internal application error has occurred.');
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|