Skip to content

Uncatchable error in WebSocketStream #27769

Closed
@quentinadam

Description

Version: Deno 2.1.6

When using WebSocketStream to open a websocket connection to a server that returns a non-2xx status code (for example 400 or 403), an error is thrown that is not catchable in a try-catch, hence terminating the Deno program.

Test program:

try {
  const wss = new WebSocketStream('wss://socket.b2c2.net/quotes');
  const connection = await wss.opened;
  const reader = connection.readable.getReader();
  while (true) {
    const { done, value } = await reader.read();
    if (done) {
      console.log('done');
      break;
    }
    console.log(value);
  }
} catch (error) {
  console.log('Error catched:', error);
}

Run with:

deno run -A --unstable-net test.ts

The program terminates with the following error:

error: Uncaught (in promise) WebSocketError: failed to connect to WebSocket: Invalid status code 400 Bad Request
    at ext:deno_websocket/02_websocketstream.js:373:19
    at eventLoopTick (ext:core/01_core.js:175:7)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions