Skip to content

Commit ccbf54f

Browse files
committed
save
1 parent 38ad346 commit ccbf54f

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public function request(string $url, array $options = []): mixed
9595
$this->process($address);
9696
} catch (Throwable $exception) {
9797
$this->deferError($options, $exception);
98+
if ($isCoroutine) {
99+
throw $exception;
100+
}
98101
return null;
99102
}
100103
if ($isCoroutine) {

tests/RequestTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ public function testException()
6161
$this->assertTrue($errorCalled);
6262
}
6363

64+
public function testBadAddressException()
65+
{
66+
$successCalled = false;
67+
$errorCalled = false;
68+
$http = new Client();
69+
$http->get(':bad_address/exception', function ($response) use (&$successCalled) {
70+
$successCalled = true;
71+
}, function ($exception) use (&$errorCalled) {
72+
$errorCalled = true;
73+
});
74+
for ($i = 0; $i < 10; $i++) {
75+
if ($successCalled || $errorCalled) {
76+
break;
77+
}
78+
Timer::sleep(0.1);
79+
}
80+
$this->assertFalse($successCalled);
81+
$this->assertTrue($errorCalled);
82+
}
83+
6484
/**
6585
* Test POST request with callbacks
6686
*/
@@ -298,4 +318,24 @@ public function testSynchronousException()
298318

299319
}
300320

321+
public function testSynchronousBadAddressException()
322+
{
323+
$throw = false;
324+
try {
325+
$http = new Client();
326+
$options = [
327+
'method' => 'POST',
328+
'version' => '1.1',
329+
'data' => ['key1' => 'value1', 'key2' => 'value2'],
330+
];
331+
$http->request(':bad_address/exception', $options);
332+
} catch (Throwable $e) {
333+
$throw = true;
334+
$this->assertInstanceOf(RuntimeException::class, $e);
335+
}
336+
337+
$this->assertTrue($throw);
338+
339+
}
340+
301341
}

0 commit comments

Comments
 (0)