Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled promise rejection with DomainException: HTTP/1.1 200 OK #149

Open
dam2k opened this issue Sep 2, 2023 · 0 comments
Open

Unhandled promise rejection with DomainException: HTTP/1.1 200 OK #149

dam2k opened this issue Sep 2, 2023 · 0 comments

Comments

@dam2k
Copy link

dam2k commented Sep 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant