IcingaEndpoint: give meaningful error...

...when trying to get an ApiUser where there is no such
This commit is contained in:
Thomas Gelf 2022-07-12 10:00:58 +02:00
parent b4c05738ae
commit d13919681a

View File

@ -8,6 +8,7 @@ use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use InvalidArgumentException;
use RuntimeException;
class IcingaEndpoint extends IcingaObject
{
@ -42,10 +43,12 @@ class IcingaEndpoint extends IcingaObject
public function getApiUser()
{
return $this->getRelatedObject(
'apiuser',
$this->getResolvedProperty('apiuser_id')
);
$id = $this->getResolvedProperty('apiuser_id');
if ($id === null) {
throw new RuntimeException('Trying to get API User for Endpoint without such: ' . $this->getObjectName());
}
return $this->getRelatedObject('apiuser', $id);
}
/**