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

Uncatchable error in WebSocketStream #27769

Open
quentinadam opened this issue Jan 22, 2025 · 0 comments
Open

Uncatchable error in WebSocketStream #27769

quentinadam opened this issue Jan 22, 2025 · 0 comments

Comments

@quentinadam
Copy link

quentinadam commented Jan 22, 2025

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)
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