Skip to content

Commit d0c1065

Browse files
committed
Throw StreamStopException when stream is stopped instead of just RuntimeException
1 parent ab62a2d commit d0c1065

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\RoadRunner\Http\Exception;
6+
7+
final class StreamStoppedException extends \RuntimeException
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct('Stream has been stopped by the client.');
12+
}
13+
}

src/HttpWorker.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Spiral\RoadRunner\Http;
66

77
use Generator;
8+
use Spiral\RoadRunner\Http\Exception\StreamStoppedException;
89
use Spiral\RoadRunner\Message\Command\StreamStop;
910
use Spiral\RoadRunner\Payload;
1011
use Spiral\RoadRunner\WorkerInterface;
@@ -93,7 +94,7 @@ private function respondStream(int $status, Generator $body, array $headers = []
9394
}
9495
$content = (string)$body->current();
9596
if ($this->worker->getPayload(StreamStop::class) !== null) {
96-
$body->throw(new \RuntimeException('Stream has been stopped by the client.'));
97+
$body->throw(new StreamStoppedException());
9798
return;
9899
}
99100
$this->worker->respond(new Payload($content, $head, false));

tests/Feature/StreamResponseTest.php

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

77
use PHPUnit\Framework\TestCase;
88
use Spiral\Goridge\SocketRelay;
9+
use Spiral\RoadRunner\Http\Exception\StreamStoppedException;
910
use Spiral\RoadRunner\Http\HttpWorker;
1011
use Spiral\RoadRunner\Payload;
1112
use Spiral\RoadRunner\Tests\Http\Server\Command\BaseCommand;
@@ -80,7 +81,7 @@ public function testStopStreamResponse(): void
8081
$this->sendCommand(new StreamStop());
8182
try {
8283
yield ' Wo';
83-
} catch (\Throwable $e) {
84+
} catch (StreamStoppedException $e) {
8485
return;
8586
}
8687
yield 'rld';

0 commit comments

Comments
 (0)