rust_blocktank_client/
error.rs

1use thiserror::Error;
2use reqwest::Error as ReqwestError;
3use url::ParseError;
4use crate::BtChannelOrderErrorType;
5
6// Error message constants
7pub const ERR_INIT_HTTP_CLIENT: &str = "Failed to initialize HTTP client";
8pub const ERR_LSP_BALANCE_ZERO: &str = "lsp_balance_sat must be greater than 0";
9pub const ERR_INVOICE_SAT_ZERO: &str = "invoice_sat must be greater than 0";
10pub const ERR_NODE_ID_EMPTY: &str = "node_id cannot be empty";
11pub const ERR_ORDER_ID_CONNECTION_EMPTY: &str = "order_id and connection_string_or_pubkey cannot be empty";
12pub const ERR_INVALID_REQUEST_PARAMS: &str = "Invalid request parameters";
13pub const ERR_INVALID_REQUEST_FORMAT: &str = "Invalid request format";
14
15#[derive(Error, Debug)]
16pub enum BlocktankError {
17    #[error("HTTP client error: {0}")]
18    HttpClient(#[from] ReqwestError),
19
20    #[error("Client error: {0}")]
21    Client(String),
22
23    #[error("Blocktank error: {message} {data:?}")]
24    BlocktankClient {
25        message: String,
26        data: serde_json::Value,
27    },
28
29    #[error("URL parse error: {0}")]
30    UrlParse(#[from] ParseError),
31
32    #[error("Serialization error: {0}")]
33    Serialization(#[from] serde_json::Error),
34
35    #[error("Channel open error: {error_type:?} - {message}")]
36    ChannelOpen {
37        error_type: BtChannelOrderErrorType,
38        message: String,
39    },
40
41    #[error("Order state error: {message}")]
42    OrderState {
43        message: String
44    },
45
46    #[error("Invalid parameter: {message}")]
47    InvalidParameter {
48        message: String
49    },
50
51    #[error("Initialization error: {message}")]
52    InitializationError {
53        message: String,
54    },
55
56    #[error("Blocktank API error: {message} {data:?}")]
57    Api {
58        message: String,
59        data: serde_json::Value,
60    },
61    #[error("Blocktank DataError: {error_details}")]
62    DataError {
63        error_details: String
64    },
65}
66
67pub type Result<T> = std::result::Result<T, BlocktankError>;