Skip to content

Commit

Permalink
Return HTTP 400 on MissingParameterException
Browse files Browse the repository at this point in the history
refs #8886
  • Loading branch information
lippserd committed Apr 7, 2015
1 parent dfd8c91 commit 25736cf
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions application/controllers/ErrorController.php
Expand Up @@ -3,6 +3,7 @@

use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Exception\MissingParameterException;
use Icinga\Security\SecurityException;
use Icinga\Web\Controller\ActionController;

Expand Down Expand Up @@ -42,19 +43,26 @@ public function errorAction()
}

break;
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
if ($exception instanceof SecurityException) {
$this->getResponse()->setHttpResponseCode(403);
$this->view->message = $exception->getMessage();
break;
}
// Move to default
default:
switch (true) {
case $exception instanceof SecurityException:
$this->getResponse()->setHttpResponseCode(403);
break;
case $exception instanceof MissingParameterException:
$this->getResponse()->setHttpResponseCode(400);
$this->getResponse()->setHeader(
'X-Status-Reason',
'Missing parameter ' . $exception->getParameter()
);
break;
default:
$this->getResponse()->setHttpResponseCode(500);
break;
}
$title = preg_replace('/\r?\n.*$/s', '', $exception->getMessage());
$this->getResponse()->setHttpResponseCode(500);
$this->view->title = 'Server error: ' . $title;
$this->view->message = $exception->getMessage();
if ($this->getInvokeArg('displayExceptions') == true) {
if ($this->getInvokeArg('displayExceptions')) {
$this->view->stackTrace = $exception->getTraceAsString();
}
break;
Expand Down

0 comments on commit 25736cf

Please sign in to comment.