Skip to main content

crispy_stalker/
error.rs

1//! Stalker-specific error types.
2//!
3//! Maps to [`crispy_iptv_types::IptvError`] variants where applicable,
4//! but provides richer context for Stalker portal failures.
5
6use thiserror::Error;
7
8/// Errors produced by [`StalkerClient`](crate::StalkerClient) operations.
9#[derive(Debug, Error)]
10pub enum StalkerError {
11    /// Portal URL could not be discovered at any known path.
12    #[error("portal not found at any known path for base URL: {0}")]
13    PortalNotFound(String),
14
15    /// Handshake failed — server did not return a valid token.
16    #[error("handshake failed: {0}")]
17    HandshakeFailed(String),
18
19    /// Authentication rejected (wrong MAC, blocked account, etc.).
20    #[error("authentication failed: {0}")]
21    Auth(String),
22
23    /// Session token expired — must re-authenticate.
24    #[error("session expired")]
25    SessionExpired,
26
27    /// Server returned data in an unexpected format.
28    #[error("unexpected response: {0}")]
29    UnexpectedResponse(String),
30
31    /// HTTP / network transport error.
32    #[error("network error: {0}")]
33    Network(#[from] reqwest::Error),
34
35    /// URL parsing failure.
36    #[error("invalid URL: {0}")]
37    InvalidUrl(#[from] url::ParseError),
38
39    /// JSON deserialization failure.
40    #[error("JSON parse error: {0}")]
41    Json(#[from] serde_json::Error),
42
43    /// Client has not been authenticated yet.
44    #[error("not authenticated — call authenticate() first")]
45    NotAuthenticated,
46}
47
48impl From<&StalkerError> for crispy_iptv_types::IptvError {
49    fn from(e: &StalkerError) -> Self {
50        match e {
51            StalkerError::Auth(msg) => crispy_iptv_types::IptvError::Auth(msg.clone()),
52            StalkerError::SessionExpired => {
53                crispy_iptv_types::IptvError::SessionExpired("stalker session expired".into())
54            }
55            StalkerError::Network(e) => crispy_iptv_types::IptvError::Network(e.to_string()),
56            StalkerError::InvalidUrl(e) => crispy_iptv_types::IptvError::InvalidUrl(e.to_string()),
57            other => crispy_iptv_types::IptvError::UnexpectedResponse(other.to_string()),
58        }
59    }
60}