Skip to content
Snippets Groups Projects
Unverified Commit 07f7f5c0 authored by scratchyone's avatar scratchyone
Browse files

Fix panic on error

parent 7cfe5d00
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
//! ``` //! ```
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use log::trace; use log::{error, trace};
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use thiserror::Error; use thiserror::Error;
...@@ -103,7 +103,7 @@ pub enum ConnectionStatus { ...@@ -103,7 +103,7 @@ pub enum ConnectionStatus {
/// Connected to a server /// Connected to a server
Connected, Connected,
/// Disconnected from a server due to an error /// Disconnected from a server due to an error
Error(ErrorEvent), Error,
/// Disconnected from a server without an error /// Disconnected from a server without an error
Disconnected, Disconnected,
} }
...@@ -148,7 +148,7 @@ impl PollingClient { ...@@ -148,7 +148,7 @@ impl PollingClient {
let status_ref = status.clone(); let status_ref = status.clone();
client.set_on_error(Some(Box::new(move |e| { client.set_on_error(Some(Box::new(move |e| {
*status_ref.borrow_mut() = ConnectionStatus::Error(e); *status_ref.borrow_mut() = ConnectionStatus::Error;
}))); })));
let status_ref = status.clone(); let status_ref = status.clone();
...@@ -238,7 +238,7 @@ impl EventClient { ...@@ -238,7 +238,7 @@ impl EventClient {
let ws: web_sys::WebSocket = match WebSocket::new(url) { let ws: web_sys::WebSocket = match WebSocket::new(url) {
Ok(ws) => ws, Ok(ws) => ws,
Err(e) => Err(WebSocketError::ConnectionCreationError( Err(e) => Err(WebSocketError::ConnectionCreationError(
e.as_string().unwrap(), "Failed to connect".into(),
))?, ))?,
}; };
// For small binary messages, like CBOR, Arraybuffer is more efficient than Blob handling // For small binary messages, like CBOR, Arraybuffer is more efficient than Blob handling
...@@ -252,7 +252,7 @@ impl EventClient { ...@@ -252,7 +252,7 @@ impl EventClient {
let on_error_ref = on_error.clone(); let on_error_ref = on_error.clone();
let onerror_callback = Closure::wrap(Box::new(move |e: ErrorEvent| { let onerror_callback = Closure::wrap(Box::new(move |e: ErrorEvent| {
*ref_status.borrow_mut() = ConnectionStatus::Error(e.clone()); *ref_status.borrow_mut() = ConnectionStatus::Error;
if let Some(f) = &*on_error_ref.borrow() { if let Some(f) = &*on_error_ref.borrow() {
f.as_ref()(e); f.as_ref()(e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment