pub struct WsError { /* private fields */ }Expand description
Extended WebSocket error with classification.
This struct wraps WebSocket errors with additional metadata including:
- Error kind (transient or permanent)
- Human-readable message
- Optional source error for error chaining
§Example
use ccxt_core::ws_client::{WsError, WsErrorKind};
// Create a transient error
let err = WsError::transient("Connection reset by peer");
assert!(err.is_transient());
assert_eq!(err.kind(), WsErrorKind::Transient);
// Create a permanent error
let err = WsError::permanent("Authentication failed: invalid API key");
assert!(!err.is_transient());
assert_eq!(err.kind(), WsErrorKind::Permanent);Implementations§
Source§impl WsError
impl WsError
Sourcepub fn new(kind: WsErrorKind, message: impl Into<String>) -> WsError
pub fn new(kind: WsErrorKind, message: impl Into<String>) -> WsError
Creates a new WsError with the specified kind and message.
§Arguments
kind- The error classification (transient or permanent)message- Human-readable error message
§Example
use ccxt_core::ws_client::{WsError, WsErrorKind};
let err = WsError::new(WsErrorKind::Transient, "Connection timeout");
assert!(err.is_transient());Sourcepub fn with_source<E>(
kind: WsErrorKind,
message: impl Into<String>,
source: E,
) -> WsError
pub fn with_source<E>( kind: WsErrorKind, message: impl Into<String>, source: E, ) -> WsError
Creates a new WsError with a source error.
§Arguments
kind- The error classification (transient or permanent)message- Human-readable error messagesource- The underlying error that caused this error
§Example
use ccxt_core::ws_client::{WsError, WsErrorKind};
use std::io;
let io_err = io::Error::new(io::ErrorKind::ConnectionReset, "connection reset");
let err = WsError::with_source(
WsErrorKind::Transient,
"Connection lost",
io_err
);
assert!(err.source().is_some());Sourcepub fn transient_with_source<E>(
message: impl Into<String>,
source: E,
) -> WsError
pub fn transient_with_source<E>( message: impl Into<String>, source: E, ) -> WsError
Creates a transient error with a source.
§Arguments
message- Human-readable error messagesource- The underlying error that caused this error
Sourcepub fn permanent(message: impl Into<String>) -> WsError
pub fn permanent(message: impl Into<String>) -> WsError
Creates a permanent error.
Permanent errors should not be retried as they indicate a fundamental issue that won’t resolve with retries.
§Arguments
message- Human-readable error message
§Example
use ccxt_core::ws_client::WsError;
let err = WsError::permanent("Invalid API key");
assert!(!err.is_transient());Sourcepub fn permanent_with_source<E>(
message: impl Into<String>,
source: E,
) -> WsError
pub fn permanent_with_source<E>( message: impl Into<String>, source: E, ) -> WsError
Creates a permanent error with a source.
§Arguments
message- Human-readable error messagesource- The underlying error that caused this error
Sourcepub fn kind(&self) -> WsErrorKind
pub fn kind(&self) -> WsErrorKind
Returns the error kind.
§Example
use ccxt_core::ws_client::{WsError, WsErrorKind};
let err = WsError::transient("timeout");
assert_eq!(err.kind(), WsErrorKind::Transient);Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns the error message.
§Example
use ccxt_core::ws_client::WsError;
let err = WsError::transient("Connection timeout");
assert_eq!(err.message(), "Connection timeout");Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Returns true if this is a transient error.
Transient errors may recover with retry.
§Example
use ccxt_core::ws_client::WsError;
let err = WsError::transient("timeout");
assert!(err.is_transient());
let err = WsError::permanent("auth failed");
assert!(!err.is_transient());Sourcepub fn is_permanent(&self) -> bool
pub fn is_permanent(&self) -> bool
Returns true if this is a permanent error.
Permanent errors should not be retried.
§Example
use ccxt_core::ws_client::WsError;
let err = WsError::permanent("auth failed");
assert!(err.is_permanent());
let err = WsError::transient("timeout");
assert!(!err.is_permanent());Sourcepub fn source(&self) -> Option<&(dyn Error + Sync + Send + 'static)>
pub fn source(&self) -> Option<&(dyn Error + Sync + Send + 'static)>
Returns the source error, if any.
§Example
use ccxt_core::ws_client::WsError;
use std::io;
let io_err = io::Error::new(io::ErrorKind::ConnectionReset, "reset");
let err = WsError::transient_with_source("Connection lost", io_err);
assert!(err.source().is_some());Source§impl WsError
impl WsError
Sourcepub fn from_tungstenite(err: &Error) -> WsError
pub fn from_tungstenite(err: &Error) -> WsError
Classifies a tungstenite WebSocket error.
This method analyzes the error type and classifies it as either transient (retryable) or permanent (non-retryable).
§Classification Rules
§Transient Errors (retryable)
- IO errors (network issues, connection resets)
ConnectionClosed(server closed connection)AlreadyClosed(connection was already closed)- Server errors (5xx HTTP status codes)
§Permanent Errors (non-retryable)
- Protocol errors (WebSocket protocol violations)
- UTF-8 encoding errors
- Authentication errors (401/403 HTTP status codes)
- Client errors (4xx HTTP status codes, except 5xx)
§Arguments
err- The tungstenite error to classify
§Example
use ccxt_core::ws_client::WsError;
use tokio_tungstenite::tungstenite::Error as TungError;
// IO errors are transient
let io_err = std::io::Error::new(std::io::ErrorKind::ConnectionReset, "reset");
let ws_err = WsError::from_tungstenite(&TungError::Io(io_err));
assert!(ws_err.is_transient());Sourcepub fn from_error(err: &Error) -> WsError
pub fn from_error(err: &Error) -> WsError
Classifies a generic error and wraps it in a WsError.
This is a convenience method for wrapping arbitrary errors. By default, unknown errors are classified as transient.
§Arguments
err- The error to classify
§Example
use ccxt_core::ws_client::WsError;
use ccxt_core::error::Error;
let err = Error::network("Connection failed");
let ws_err = WsError::from_error(&err);
assert!(ws_err.is_transient());Trait Implementations§
Source§impl Error for WsError
impl Error for WsError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl Freeze for WsError
impl !RefUnwindSafe for WsError
impl Send for WsError
impl Sync for WsError
impl Unpin for WsError
impl !UnwindSafe for WsError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.