Skip to content

Commit 16b1c99

Browse files
grongorsimPod
authored andcommitted
Catch TimeoutException in FallbackSnmpClient
1 parent 8bdbd9f commit 16b1c99

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Transport/FallbackSnmpClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Psr\Log\LoggerInterface;
88
use SimPod\PhpSnmp\Exception\GeneralException;
9+
use SimPod\PhpSnmp\Exception\TimeoutReached;
910

1011
final class FallbackSnmpClient implements SnmpClient
1112
{
@@ -76,7 +77,7 @@ private function tryClients(callable $requestCallback) : array
7677
foreach ($this->snmpClients as $key => $snmpClient) {
7778
try {
7879
return $requestCallback($snmpClient);
79-
} catch (GeneralException $exception) {
80+
} catch (GeneralException | TimeoutReached $exception) {
8081
$this->logger->warning(
8182
'SNMP request failed',
8283
[

tests/Transport/FallbackSnmpClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Psr\Log\NullLogger;
99
use Psr\Log\Test\TestLogger;
1010
use SimPod\PhpSnmp\Exception\GeneralException;
11+
use SimPod\PhpSnmp\Exception\TimeoutReached;
1112
use SimPod\PhpSnmp\Transport\FallbackSnmpClient;
1213
use SimPod\PhpSnmp\Transport\Request;
1314
use SimPod\PhpSnmp\Transport\SnmpClient;
@@ -82,7 +83,7 @@ public function testOnlyLastClientWorks() : void
8283
$client1->expects(self::once())
8384
->method('get')
8485
->with($oids = ['.1.2.3'])
85-
->willThrowException($exception1 = GeneralException::new('an error'));
86+
->willThrowException($exception1 = TimeoutReached::fromOid('127.0.0.1', '.1.2.3'));
8687

8788
$client2 = $this->createMock(SnmpClient::class);
8889
$client2->expects(self::once())

0 commit comments

Comments
 (0)