lit_sdk/
error.rs

1use reqwest::header::ToStrError;
2use thiserror::Error;
3
4/// Errors produced by this crate
5#[derive(Debug, Error)]
6pub enum SdkError {
7    /// Errors from IO
8    #[error("I/O error: {0}")]
9    Io(#[from] std::io::Error),
10    /// Errors from inner crate `reqwest`
11    #[error("Reqwest error: {0}")]
12    Reqwest(#[from] reqwest::Error),
13    /// Error when converting an HTTP response header to a string
14    #[error("Http header to string error: {0}")]
15    HeaderToStr(#[from] ToStrError),
16    /// Errors from inner crate `serde_json`
17    #[error("Serde error: {0}")]
18    Json(#[from] serde_json::Error),
19    /// Errors from the hex crate
20    #[error("Hex error: {0}")]
21    Hex(#[from] hex::FromHexError),
22    /// Signature errors from the ecdsa crate
23    #[error("Signature error: {0}")]
24    EcdsaSignature(#[from] ecdsa::signature::Error),
25    /// Bls errors from the blsful crate
26    #[error("Bls error: {0}")]
27    Bls(#[from] lit_node_core::lit_rust_crypto::blsful::BlsError),
28    /// Errors from string parsing
29    #[error("String parse error: {0}")]
30    Parse(String),
31    /// Errors from calling the build methods on Request builders
32    #[error("Build request error: {0}")]
33    Build(String),
34    /// Errors from decrypting a payload
35    #[error("Decryption error: {0}")]
36    Decryption(String),
37    /// Errors from attestation verification
38    #[error("The Attestation report data doesn't match the provided data")]
39    Attestation,
40    /// Errors when converting between types
41    #[error("Invalid type conversion: {0}")]
42    InvalidType(String),
43    /// Signature combination errors
44    #[error("An error occurred while combining signatures: {0}")]
45    SignatureCombine(String),
46    /// Signature verification error
47    #[error("Signature does not verify with the given message and public key")]
48    SignatureVerify,
49    /// Errors from admin endpoints
50    #[error("Admin endpoint error: {0}")]
51    Admin(String),
52}
53
54/// Results produced by this crate
55pub type SdkResult<T> = Result<T, SdkError>;
56
57impl From<lit_node_core::Error> for SdkError {
58    fn from(e: lit_node_core::Error) -> Self {
59        match e {
60            lit_node_core::Error::Parse(e) => SdkError::Parse(e),
61            lit_node_core::Error::InvalidType(e) => SdkError::InvalidType(e),
62        }
63    }
64}