Prechádzať zdrojové kódy

fix: Unknown Error response error

thesimplekid 11 mesiacov pred
rodič
commit
b2e6d26f31

+ 4 - 4
crates/cdk/src/client.rs

@@ -27,14 +27,14 @@ pub enum Error {
     /// From hex error
     #[error(transparent)]
     ReqwestError(#[from] reqwest::Error),
-    ///  Min req error
-    #[error("Unknown Error response")]
-    UnknownErrorResponse(crate::error::ErrorResponse),
+    ///  Unknown error response
+    #[error("Unknown Error response: `{0}`")]
+    UnknownErrorResponse(String),
 }
 
 impl From<ErrorResponse> for Error {
     fn from(err: ErrorResponse) -> Error {
-        Self::UnknownErrorResponse(err)
+        Self::UnknownErrorResponse(err.to_string())
     }
 }
 

+ 13 - 0
crates/cdk/src/error.rs

@@ -1,5 +1,6 @@
 //! Errors
 
+use std::fmt;
 use std::string::FromUtf8Error;
 
 use serde::{Deserialize, Serialize};
@@ -82,6 +83,18 @@ pub struct ErrorResponse {
     pub detail: Option<String>,
 }
 
+impl fmt::Display for ErrorResponse {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(
+            f,
+            "code: {}, error: {}, detail: {}",
+            self.code,
+            self.error.clone().unwrap_or_default(),
+            self.detail.clone().unwrap_or_default()
+        )
+    }
+}
+
 impl ErrorResponse {
     pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
         if let Ok(res) = serde_json::from_str::<ErrorResponse>(json) {

+ 0 - 2
crates/cdk/src/nuts/nut13.rs

@@ -15,7 +15,6 @@ use crate::{Amount, SECP256K1};
 
 impl Secret {
     pub fn from_xpriv(xpriv: ExtendedPrivKey, keyset_id: Id, counter: u32) -> Result<Self, Error> {
-        tracing::debug!("Deriving secret for {} with count {}", keyset_id, counter);
         let path = derive_path_from_keyset_id(keyset_id)?
             .child(ChildNumber::from_hardened_idx(counter)?)
             .child(ChildNumber::from_normal_idx(0)?);
@@ -29,7 +28,6 @@ impl Secret {
 
 impl SecretKey {
     pub fn from_xpriv(xpriv: ExtendedPrivKey, keyset_id: Id, counter: u32) -> Result<Self, Error> {
-        tracing::debug!("Deriving key for {} with count {}", keyset_id, counter);
         let path = derive_path_from_keyset_id(keyset_id)?
             .child(ChildNumber::from_hardened_idx(counter)?)
             .child(ChildNumber::from_normal_idx(1)?);