CommandTransport: Return result in method send()

This commit is contained in:
Johannes Meyer 2021-05-04 15:24:14 +02:00
parent 82e86b3c14
commit 3657a820fc
2 changed files with 9 additions and 7 deletions

View file

@ -249,14 +249,16 @@ class ApiCommandTransport implements CommandTransportInterface
return;
}
$result = array_pop($responseData['results']);
if ($result['code'] < 200 || $result['code'] >= 300) {
$errorResult = $responseData['results'][0];
if (isset($errorResult['code']) && ($errorResult['code'] < 200 || $errorResult['code'] >= 300)) {
throw new ApiCommandException(
'Can\'t send external Icinga command: %u %s',
$result['code'],
$result['status']
$errorResult['code'],
$errorResult['status']
);
}
return $responseData['results'];
}
/**
@ -269,7 +271,7 @@ class ApiCommandTransport implements CommandTransportInterface
*/
public function send(IcingaCommand $command, $now = null)
{
$this->sendCommand($this->renderer->render($command));
return $this->sendCommand($this->renderer->render($command));
}
/**

View file

@ -106,14 +106,14 @@ class CommandTransport implements CommandTransportInterface
$transport = static::createTransport($transportConfig);
try {
$transport->send($command, $now);
$result = $transport->send($command, $now);
} catch (CommandTransportException $e) {
Logger::error($e);
$errors[] = sprintf('%s: %s.', $name, rtrim($e->getMessage(), '.'));
continue; // Try the next transport
}
return; // The command was successfully sent
return $result; // The command was successfully sent
}
if (! empty($errors)) {