catch VMService connection exception (#6526)

This commit is contained in:
Dan Rubel 2016-10-27 09:14:41 +01:00 committed by GitHub
parent 0b49d81cb2
commit ca90656fba

View File

@ -25,7 +25,12 @@ class VMService {
/// Connect to '127.0.0.1' at [port].
static Future<VMService> connect(int port) async {
Uri uri = new Uri(scheme: 'ws', host: '127.0.0.1', port: port, path: 'ws');
WebSocket ws = await WebSocket.connect(uri.toString());
WebSocket ws;
try {
ws = await WebSocket.connect(uri.toString());
} catch (e) {
return new Future<VMService>.error('Failed to connect to $uri\n $e');
}
rpc.Peer peer = new rpc.Peer(new IOWebSocketChannel(ws).cast());
peer.listen();
Uri httpAddress = new Uri(scheme: 'http', host: '127.0.0.1', port: port);