Friendlier error controller, special handling for 404 with disabled module

This commit is contained in:
Thomas Gelf 2014-03-25 12:10:02 +00:00
parent f802b36ca9
commit f612610fa7
2 changed files with 26 additions and 7 deletions

View File

@ -30,7 +30,8 @@
# namespace Icinga\Application\Controllers;
use \Icinga\Web\Controller\ActionController;
use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga;
/**
* Application wide controller for displaying exceptions
@ -50,17 +51,29 @@ class ErrorController extends ActionController
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
$modules = Icinga::app()->getModuleManager();
$path = ltrim($this->_request->get('PATH_INFO'), '/');
$path = preg_split('~/~', $path);
$path = array_shift($path);
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
$this->view->message = $this->translate('Page not found.');
if ($modules->hasInstalled($path) && ! $modules->hasEnabled($path)) {
$this->view->message .= ' ' . sprintf(
$this->translate('Enabling the "%s" module might help!'),
$path
);
}
break;
default:
$this->getResponse()->setHttpResponseCode(500);
$this->view->title = 'Server error';
$this->view->message = $exception->getMessage();
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->stackTrace = $exception->getTraceAsString();
}
break;
}
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->stackTrace = $exception->getTraceAsString();
}
$this->view->request = $error->request;
}
}

View File

@ -1,7 +1,13 @@
<h1 class="alert alert-danger"><?= $message ?></h1>
<?php if ($this->title): ?>
<div class="controls">
<h1><?= $this->escape($title) ?></h1>
</div>
<?php endif ?>
<div class="content">
<p><strong><?= $this->escape($message) ?></strong></p>
<?php if (isset($stackTrace)) : ?>
<hr />
<pre><?= $stackTrace ?></pre>
<pre><?= $this->escape($stackTrace) ?></pre>
<?php endif ?>
<?php if (isset($this->messageBox)) : ?>
<?= $this->messageBox->render(); ?>