breez_sdk_core/swap_in/
error.rs1use crate::{error::SdkError, persist::error::PersistError};
2
3pub type SwapResult<T, E = SwapError> = Result<T, E>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum SwapError {
7 #[error("{0}")]
8 Generic(String),
9
10 #[error(transparent)]
11 Persistance(#[from] PersistError),
12
13 #[error("{0}")]
14 ServiceConnectivity(String),
15
16 #[error("{0}")]
17 UnsupportedSwapLimits(String),
18}
19
20impl SwapError {
21 pub(crate) fn generic(err: &str) -> Self {
22 Self::Generic(err.to_string())
23 }
24
25 pub(crate) fn unsupported_swap_limits(err: &str) -> Self {
26 Self::UnsupportedSwapLimits(err.to_string())
27 }
28}
29
30impl From<anyhow::Error> for SwapError {
31 fn from(err: anyhow::Error) -> Self {
32 Self::Generic(err.to_string())
33 }
34}
35
36impl From<SdkError> for SwapError {
37 fn from(value: SdkError) -> Self {
38 match value {
39 SdkError::Generic { err } => Self::Generic(err),
40 SdkError::ServiceConnectivity { err } => Self::ServiceConnectivity(err),
41 }
42 }
43}
44
45impl From<tonic::Status> for SwapError {
46 fn from(status: tonic::Status) -> Self {
47 Self::Generic(sdk_common::tonic_wrap::Status(status).to_string())
48 }
49}