diff options
author | 2024-03-30 20:59:54 +0100 | |
---|---|---|
committer | 2024-03-30 20:59:58 +0100 | |
commit | 7af7a7626a8e83fe3f9c3b0d2ad7d2b32da41d45 (patch) | |
tree | 319b9976f6274f42e748d1b501229bb219584f66 /src/error.rs | |
parent | c6745a22e79f0556a19b0d44a181fb9d8ed78f90 (diff) |
WARNING: unstable commit.
🔧 Update .gitignore to exclude .vscode directory
✨ Add futures-util and url dependencies to Cargo.toml
♻️ Refactor error handling into separate error module in Rust project
💡 Add get_password method documentation in connection_details.rs
♻️ Replace String with Transport enum for forced_transport in connection_options.rs
✨ Implement WebSocket connection logic in ls_client.rs with async support
✨ Add ClientStatus, ConnectionType, and DisconnectionType enums to manage client states in ls_client.rs
✨ (main.rs): add Transport enum to LightstreamerClient imports for WebSocket support
♻️ (main.rs): refactor signal handling to use SharedState struct for clean shutdown
✨ (main.rs): implement AtomicBool for graceful disconnect handling
📝 (main.rs): update comments to reflect new signal handling logic
✨ (main.rs): set forced transport to WebSocket streaming in Lightstreamer client options
✨ (util.rs): create new util module with clean_message function for message sanitization
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..9c3a916 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,70 @@ +use std::fmt; +use std::error::Error; + +#[derive(Debug)] +pub struct IllegalArgumentException(String); + +impl IllegalArgumentException { + pub fn new(msg: &str) -> IllegalArgumentException { + IllegalArgumentException(msg.to_string()) + } +} + +impl fmt::Display for IllegalArgumentException { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl Error for IllegalArgumentException { + fn description(&self) -> &str { + &self.0 + } +} + +impl From<Box<dyn Error>> for IllegalArgumentException { + fn from(error: Box<dyn Error>) -> Self { + IllegalArgumentException::new(&error.to_string()) + } +} + +#[derive(Debug)] +pub struct IllegalStateException { + details: String +} + +impl IllegalStateException { + pub fn new(msg: &str) -> IllegalStateException { + IllegalStateException{details: msg.to_string()} + } +} + +impl fmt::Display for IllegalStateException { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f,"{}",self.details) + } +} + +impl Error for IllegalStateException { + fn description(&self) -> &str { + &self.details + } +} + +impl From<Box<dyn Error>> for IllegalStateException { + fn from(error: Box<dyn Error>) -> Self { + IllegalStateException::new(&error.to_string()) + } +} + +impl From<serde_urlencoded::ser::Error> for IllegalStateException { + fn from(err: serde_urlencoded::ser::Error) -> Self { + IllegalStateException::new(&format!("Serialization error: {}", err)) + } +} + +impl From<tokio_tungstenite::tungstenite::Error> for IllegalStateException { + fn from(err: tokio_tungstenite::tungstenite::Error) -> Self { + IllegalStateException::new(&format!("WebSocket error: {}", err)) + } +}
\ No newline at end of file |