ObjectController: hendly duplicate key errors

fixes #977
This commit is contained in:
Thomas Gelf 2017-06-26 14:39:35 +02:00
parent afcd928dfa
commit 1739b950a8
1 changed files with 4 additions and 0 deletions

View File

@ -6,6 +6,7 @@ use Exception;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\InvalidPropertyException;
use Icinga\Exception\NotFoundError; use Icinga\Exception\NotFoundError;
use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Web\Controller\Extension\ObjectRestrictions; use Icinga\Module\Director\Web\Controller\Extension\ObjectRestrictions;
@ -37,6 +38,9 @@ abstract class ObjectController extends ActionController
} catch (NotFoundError $e) { } catch (NotFoundError $e) {
$response->setHttpResponseCode(404); $response->setHttpResponseCode(404);
$this->sendJson($response, (object) array('error' => $e->getMessage())); $this->sendJson($response, (object) array('error' => $e->getMessage()));
} catch (DuplicateKeyException $e) {
$response->setHttpResponseCode(422);
$this->sendJson($response, (object) array('error' => $e->getMessage()));
} catch (Exception $e) { } catch (Exception $e) {
if ($response->getHttpResponseCode() === 200) { if ($response->getHttpResponseCode() === 200) {
$response->setHttpResponseCode(500); $response->setHttpResponseCode(500);