Skip to content

Commit

Permalink
Merge pull request #16 from roadrunner-php/stream-stop-exception
Browse files Browse the repository at this point in the history
Throw StreamStopException when stream is stopped instead of just RuntimeException
  • Loading branch information
butschster authored Jul 17, 2023
2 parents ab62a2d + d0c1065 commit c6e6f0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Exception/StreamStoppedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunner\Http\Exception;

final class StreamStoppedException extends \RuntimeException
{
public function __construct()
{
parent::__construct('Stream has been stopped by the client.');
}
}
3 changes: 2 additions & 1 deletion src/HttpWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Spiral\RoadRunner\Http;

use Generator;
use Spiral\RoadRunner\Http\Exception\StreamStoppedException;
use Spiral\RoadRunner\Message\Command\StreamStop;
use Spiral\RoadRunner\Payload;
use Spiral\RoadRunner\WorkerInterface;
Expand Down Expand Up @@ -93,7 +94,7 @@ private function respondStream(int $status, Generator $body, array $headers = []
}
$content = (string)$body->current();
if ($this->worker->getPayload(StreamStop::class) !== null) {
$body->throw(new \RuntimeException('Stream has been stopped by the client.'));
$body->throw(new StreamStoppedException());
return;
}
$this->worker->respond(new Payload($content, $head, false));
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/StreamResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPUnit\Framework\TestCase;
use Spiral\Goridge\SocketRelay;
use Spiral\RoadRunner\Http\Exception\StreamStoppedException;
use Spiral\RoadRunner\Http\HttpWorker;
use Spiral\RoadRunner\Payload;
use Spiral\RoadRunner\Tests\Http\Server\Command\BaseCommand;
Expand Down Expand Up @@ -80,7 +81,7 @@ public function testStopStreamResponse(): void
$this->sendCommand(new StreamStop());
try {
yield ' Wo';
} catch (\Throwable $e) {
} catch (StreamStoppedException $e) {
return;
}
yield 'rld';
Expand Down

0 comments on commit c6e6f0a

Please sign in to comment.