mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-04 21:45:24 +01:00
expose error: Token already spent.
This commit is contained in:
@@ -89,20 +89,27 @@ impl fmt::Display for Error {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct MintErrorResponse {
|
||||
code: u32,
|
||||
error: String,
|
||||
error: Option<String>,
|
||||
detail: Option<String>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn from_json(json: &str) -> Result<Self, Error> {
|
||||
let mint_res: MintErrorResponse = serde_json::from_str(json)?;
|
||||
|
||||
let mint_error = match mint_res.error {
|
||||
let err = mint_res
|
||||
.error
|
||||
.as_deref()
|
||||
.or_else(|| mint_res.detail.as_deref())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mint_error = match err {
|
||||
error if error.starts_with("Lightning invoice not paid yet.") => Error::InvoiceNotPaid,
|
||||
error if error.starts_with("Lightning wallet not responding") => {
|
||||
let mint = utils::extract_url_from_error(&error);
|
||||
Error::LightingWalletNotResponding(mint)
|
||||
}
|
||||
error => Error::Custom(error),
|
||||
error => Error::Custom(error.to_owned()),
|
||||
};
|
||||
Ok(mint_error)
|
||||
}
|
||||
@@ -459,8 +466,8 @@ impl Client {
|
||||
serde_json::from_value(res.clone());
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::from_json(&res.to_string())?),
|
||||
Ok(res) if res.promises.is_some() => Ok(res),
|
||||
_ => Err(Error::from_json(&res.to_string())?),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user