diff --git a/examples/dashboard/src/lib.rs b/examples/dashboard/src/lib.rs index cf655813eb5..db834c0ff5b 100644 --- a/examples/dashboard/src/lib.rs +++ b/examples/dashboard/src/lib.rs @@ -136,7 +136,7 @@ impl Component for Model { }); let task = self.ws_service - .connect("ws://localhost:9001/", callback, notification); + .connect("ws://localhost:9001/", callback, notification).unwrap(); self.ws = Some(task); } WsAction::SendData(binary) => { diff --git a/src/services/websocket.rs b/src/services/websocket.rs index 23c2d577f84..548ee320cee 100644 --- a/src/services/websocket.rs +++ b/src/services/websocket.rs @@ -50,11 +50,16 @@ impl WebSocketService { url: &str, callback: Callback, notification: Callback, - ) -> WebSocketTask + ) -> Result where OUT: From + From, { - let ws = WebSocket::new(url).unwrap(); + let ws = WebSocket::new(url); + if ws.is_err() { + return Err("Failed to created websocket with given URL"); + } + + let ws = ws.unwrap(); ws.set_binary_type(SocketBinaryType::ArrayBuffer); let notify = notification.clone(); ws.add_event_listener(move |_: SocketOpenEvent| { @@ -80,7 +85,7 @@ impl WebSocketService { callback.emit(out); } }); - WebSocketTask { ws, notification } + Ok(WebSocketTask { ws, notification }) } }