DeleteDowntimeCommandForm: Show error notification if not successful

resolves #4303
This commit is contained in:
Johannes Meyer 2021-02-03 15:42:13 +01:00
parent 5be964f989
commit 77ca3e0c31
1 changed files with 23 additions and 4 deletions

View File

@ -4,6 +4,7 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object;
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
use Icinga\Module\Monitoring\Exception\CommandTransportException;
use Icinga\Module\Monitoring\Forms\Command\CommandForm;
use Icinga\Web\Notification;
@ -98,13 +99,31 @@ class DeleteDowntimeCommandForm extends CommandForm
->setDowntimeId($this->getElement('downtime_id')->getValue())
->setDowntimeName($this->getElement('downtime_name')->getValue())
->setIsService($this->getElement('downtime_is_service')->getValue());
$this->getTransport($this->request)->send($cmd);
$redirect = $this->getElement('redirect')->getValue();
$errorMsg = null;
try {
$this->getTransport($this->request)->send($cmd);
} catch (CommandTransportException $e) {
$errorMsg = $e->getMessage();
}
if (! $errorMsg) {
$redirect = $this->getElement('redirect')->getValue();
Notification::success($this->translate('Deleting downtime.'));
} else {
if (! $this->getIsApiTarget()) {
$redirect = $this->getRequest()->getUrl();
}
Notification::error($errorMsg);
}
if (! empty($redirect)) {
$this->setRedirectUrl($redirect);
return true;
}
Notification::success($this->translate('Deleting downtime.'));
return true;
return false;
}
}