websocket-client icon indicating copy to clipboard operation
websocket-client copied to clipboard

Exception not reaching outer try catch

Open programmin1 opened this issue 4 years ago • 2 comments
trafficstars

I put the whole Loop doing a websocket in a try... catch( Exception $e ) {

If there is a problem, like I disconnect internet, I get...

   Amp\Websocket\ClosedException  : Connection closed abnormally while awaiting message; Code 1008 (POLICY_VIOLATION); Reason: "Exceeded unanswered PING limit"

  at .../vendor/amphp/websocket/src/Rfc6455Client.php:659
    655|                             $deferred->resolve();
    656|                             break;
    657| 
    658|                         default:
  > 659|                             $deferred->fail(new ClosedException(
    660|                                 'Connection closed abnormally while awaiting message',
    661|                                 $code,
    662|                                 $reason
    663|                             ));

  Exception trace:

  1   Amp\Websocket\Rfc6455Client::Amp\Websocket\{closure}()
      [internal]:0

  2   Generator::current()
      .../vendor/amphp/amp/lib/Coroutine.php:67

How can I catch error and retry since try/catch does not work?

programmin1 avatar May 12 '21 08:05 programmin1

How does your code look like?

kelunik avatar May 12 '21 09:05 kelunik

The same way the example on your front page works:

Loop::run(function () { ...

$connection = yield connect('wss://...')....

while ($message = yield $connection->receive()) { ...

programmin1 avatar May 14 '21 04:05 programmin1