Open Dnathan33 opened 1 year ago
Below is the implementation I am using for handling web socket requests.
WebSocketChannel.connect(Uri.parse(endpoint))
final messageController = StreamController(onCancel: () { channel.sink.close(); }); channel.stream.listen(messageController.add, cancelOnError: true, onError: (e) { messageController.addError(e); channel.sink.close(); });
When I purposefully use a wrong url. An exception is thown in the
IOWebSocketChannel.connect
function."Connection to '<URL>' was not upgraded to websocket"
Another Error
SocketException: Failed host lookup: 'URL' (OS Error: nodename nor servname provided, or not known, errno = 8)
The issue becomes that when these errors occur we handle these errors. However, even after the errors are handled the app still crashes.
Because the exceptions are inside the lib I've struggled a lot with that on desktop/web There are unhandled errors almost on every trivial case (like server is not responding) I came with idea to find another library or write my own
Same issue, using the WebSocketChannel.connect()
method throws errors even if wrapped inside a try/catch block
Same issue, using the
WebSocketChannel.connect()
method throws errors even if wrapped inside a try/catch block
Same
WebSocketChannel channel = WebSocketChannel.connect(
Uri.parse('ws://localhost:8000/ws'),
);
try {
await channel.ready;
} catch (e) {
print("Exception: $e");
}
WebSocketChannel channel = WebSocketChannel.connect( Uri.parse('ws://localhost:8000/ws'), ); try { await channel.ready; } catch (e) { print("Exception: $e"); }
If the server is down this will print something like
WebSocketChannelException: Instance of 'WebSocketException'
I didn't figure out how to extract more information about the exception, someone knows? Even doing this:
try {
await _channel.ready;
} catch(e) {
final we = e as WebSocketChannelException;
final we1 = we.inner as WebSocketException;
print('${we1.message}');
}
it spits :
Unhandled Exception: type 'WebSocketException' is not a subtype of type 'WebSocketException' in type cast where
WebSocketException is from package:web_socket/src/web_socket.dart
WebSocketException is from dart:_http
What I'm missing?
Below is the implementation I am using for handling web socket requests.
WebSocketChannel.connect(Uri.parse(endpoint))
When I purposefully use a wrong url. An exception is thown in the
IOWebSocketChannel.connect
function.Another Error
The issue becomes that when these errors occur we handle these errors. However, even after the errors are handled the app still crashes.