Browse Source

use value to return error

thesimplekid 1 year ago
parent
commit
0d64836778
2 changed files with 17 additions and 5 deletions
  1. 1 1
      Cargo.toml
  2. 16 4
      src/client.rs

+ 1 - 1
Cargo.toml

@@ -19,7 +19,7 @@ bitcoin = { version = "0.30.0", features=["serde"] }
 bitcoin_hashes = "0.12.0"
 hex = "0.4.3"
 k256 = { version = "0.13.1", features=["arithmetic"] }
-lightning-invoice = { version = "0.22.0", features=["serde"] }
+lightning-invoice = { version = "0.23.0", features=["serde"] }
 minreq = { version = "2.7.0", features = ["json-using-serde", "https"] }
 rand = "0.8.5"
 getrandom = { version = "0.2", features = ["js"] }

+ 16 - 4
src/client.rs

@@ -90,10 +90,18 @@ impl Client {
             outputs: blinded_messages.blinded_messages,
         };
 
-        Ok(minreq::post(url)
+        let res = minreq::post(url)
             .with_json(&request)?
             .send()?
-            .json::<PostMintResponse>()?)
+            .json::<Value>()?;
+
+        let response: Result<PostMintResponse, serde_json::Error> =
+            serde_json::from_value(res.clone());
+
+        match response {
+            Ok(res) => Ok(res),
+            Err(_) => Err(Error::CustomError(res.to_string())),
+        }
     }
 
     /// Check Max expected fee [NUT-05]
@@ -129,9 +137,13 @@ impl Client {
             .send()?
             .json::<Value>()?;
 
-        println!("{:?}", value);
+        let response: Result<MeltResponse, serde_json::Error> =
+            serde_json::from_value(value.clone());
 
-        Ok(serde_json::from_value(value)?)
+        match response {
+            Ok(res) => Ok(res),
+            Err(_) => Err(Error::CustomError(value.to_string())),
+        }
     }
 
     /// Split Token [NUT-06]