Pawl icon indicating copy to clipboard operation
Pawl copied to clipboard

Unhandled promise rejection with DomainException: HTTP/1.1 200 OK

Open dam2k opened this issue 1 year ago • 0 comments

Hi there. When you try to connect to a wss but the server does not upgrade the websocket, an unhandled promise rejection with DomainException is fired by vendor/ratchet/pawl/src/Connector.php at line 91.

This is my test code:

$reactConnector = new \React\Socket\Connector(['timeout' => 11]);
$loop = \React\EventLoop\Loop::get();
$connector = new \Ratchet\Client\Connector($loop, $reactConnector);
$connector('wss://www.example.com', [], ['X-myheader'=>'12345'])->then(
    function(\Ratchet\Client\WebSocket $conn) { // promise resolve
        $conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
            echo "Received: {$msg}\n";
            $conn->close();
        });
        $conn->on('close', function($code = null, $reason = null) {
            echo "Connection closed ({$code} - {$reason})\n";
        });
    },
    function (\Exception $e) use ($loop) { // promise reject
        $loop->stop();
        //echo "Could not connect: {$e->getMessage()}\n";
    }
);

I fixed the problem handling the rejected promise on ratchet/pawl/src/Connector.php at line 77. Please check the patch below, it worked for me. Thank you.

Connector.php.patch.zip

dam2k avatar Sep 02 '23 23:09 dam2k