Skip to main content

instapi360_cloud/
error.rs

1//! Error and result types for the Insta360 cloud client.
2
3use std::io;
4
5/// Result alias used throughout the crate.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// All failures the client can surface.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// Transport-level failure (DNS, TLS, connection, timeout).
12    #[error("http transport error: {0}")]
13    Http(#[from] reqwest::Error),
14
15    /// The API returned a non-zero `code`/`errCode` in its JSON envelope.
16    #[error("api error {code}: {message}")]
17    Api { code: i64, message: String },
18
19    /// Authentication / session problem (missing, expired, or rejected token).
20    #[error("auth error: {0}")]
21    Auth(String),
22
23    /// Request-signing failed or the signing scheme is not yet configured.
24    #[error("signing error: {0}")]
25    Signing(String),
26
27    /// A response body could not be decoded into the expected shape.
28    #[error("decode error: {0}")]
29    Decode(#[from] serde_json::Error),
30
31    /// Local I/O failure while writing a downloaded file.
32    #[error("io error: {0}")]
33    Io(#[from] io::Error),
34
35    /// A download ended early: fewer bytes than the server declared.
36    #[error("partial download: got {got} of {expected} bytes")]
37    Partial { got: u64, expected: u64 },
38
39    /// A downloaded part failed its MD5 integrity check.
40    #[error("checksum mismatch for {file}: expected {expected}, got {got}")]
41    Checksum {
42        file: String,
43        expected: String,
44        got: String,
45    },
46
47    /// A malformed or unexpected URL.
48    #[error("invalid url: {0}")]
49    Url(#[from] url::ParseError),
50}
51
52impl Error {
53    /// True when re-authenticating (refresh / re-login) is the right recovery.
54    pub fn is_auth(&self) -> bool {
55        matches!(self, Error::Auth(_))
56    }
57}