diff --git a/src/client.rs b/src/client.rs index d72c48bc..e83f8416 100644 --- a/src/client.rs +++ b/src/client.rs @@ -64,7 +64,14 @@ impl Client { /// Get Keysets [NUT-02] pub async fn get_keysets(&self) -> Result { let url = self.mint_url.join("keysets")?; - Ok(minreq::get(url).send()?.json::()?) + let res = minreq::get(url).send()?.json::()?; + + let response: Result = serde_json::from_value(res.clone()); + + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } /// Request Mint [NUT-03] @@ -73,7 +80,15 @@ impl Client { url.query_pairs_mut() .append_pair("amount", &amount.to_sat().to_string()); - Ok(minreq::get(url).send()?.json::()?) + let res = minreq::get(url).send()?.json::()?; + + let response: Result = + serde_json::from_value(res.clone()); + + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } /// Mint Tokens [NUT-04] @@ -109,10 +124,18 @@ impl Client { let request = CheckFeesRequest { pr: invoice }; - Ok(minreq::post(url) + let res = minreq::post(url) .with_json(&request)? .send()? - .json::()?) + .json::()?; + + let response: Result = + serde_json::from_value(res.clone()); + + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } /// Melt [NUT-05] @@ -154,11 +177,13 @@ impl Client { .send()? .json::()?; - // TODO: need to handle response error - // specifically token already spent - println!("Split Res: {:?}", res); + let response: Result = + serde_json::from_value(res.clone()); - Ok(serde_json::from_value(res)?) + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } /// Spendable check [NUT-07] @@ -171,10 +196,18 @@ impl Client { proofs: proofs.to_owned(), }; - Ok(minreq::post(url) + let res = minreq::post(url) .with_json(&request)? .send()? - .json::()?) + .json::()?; + + let response: Result = + serde_json::from_value(res.clone()); + + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } /// Get Mint Info [NUT-09] @@ -182,6 +215,11 @@ impl Client { let url = self.mint_url.join("info")?; let res = minreq::get(url).send()?.json::()?; - Ok(serde_json::from_value(res)?) + let response: Result = serde_json::from_value(res.clone()); + + match response { + Ok(res) => Ok(res), + Err(_) => Err(Error::CustomError(res.to_string())), + } } }