rust_blocktank_client/
error.rs

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