Skip to content

Commit

Permalink
Fix panic on error
Browse files Browse the repository at this point in the history
  • Loading branch information
scratchyone committed Jan 6, 2021
1 parent 7cfe5d0 commit 07f7f5c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
//! ```
#[cfg(test)]
mod tests;
use log::trace;
use log::{error, trace};
use std::cell::RefCell;
use std::rc::Rc;
use thiserror::Error;
Expand All @@ -103,7 +103,7 @@ pub enum ConnectionStatus {
/// Connected to a server
Connected,
/// Disconnected from a server due to an error
Error(ErrorEvent),
Error,
/// Disconnected from a server without an error
Disconnected,
}
Expand Down Expand Up @@ -148,7 +148,7 @@ impl PollingClient {
let status_ref = status.clone();

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();
Expand Down Expand Up @@ -238,7 +238,7 @@ impl EventClient {
let ws: web_sys::WebSocket = match WebSocket::new(url) {
Ok(ws) => ws,
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
Expand All @@ -252,7 +252,7 @@ impl EventClient {
let on_error_ref = on_error.clone();

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() {
f.as_ref()(e);
}
Expand Down

0 comments on commit 07f7f5c

Please sign in to comment.