Skip to content

Commit

Permalink
chore: rename error to detail in error-response
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 6, 2023
1 parent b9320a7 commit e3c9475
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions flutter/native/src/wasm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ async fn extract_response_data<T: serde::de::DeserializeOwned>(
.unwrap();

// FIXME: use the error code to return a proper error
match data.error.as_str() {
match data.detail.as_str() {
"Lightning invoice not paid yet." => {
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.error))
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.detail))
}
_ => Err(MokshaWalletError::MintError(data.error)),
_ => Err(MokshaWalletError::MintError(data.detail)),
}
}
}
Expand All @@ -152,11 +152,11 @@ async fn extract_response_data<T: serde::de::DeserializeOwned>(
.unwrap();

// FIXME: use the error code to return a proper error
match data.error.as_str() {
match data.detail.as_str() {
"Lightning invoice not paid yet." => {
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.error))
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.detail))
}
_ => Err(MokshaWalletError::MintError(data.error)),
_ => Err(MokshaWalletError::MintError(data.detail)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl PostSwapResponse {
#[derive(Deserialize, Debug)]
pub struct CashuErrorResponse {
pub code: u64,
pub error: String,
pub detail: String,
}

#[skip_serializing_none]
Expand Down
2 changes: 1 addition & 1 deletion moksha-mint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl IntoResponse for MokshaMintError {

let body = Json(json!({
"code": 0,
"error": self.to_string(),
"detail": self.to_string(),
}));

(status, body).into_response()
Expand Down
16 changes: 8 additions & 8 deletions moksha-wallet/src/client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ async fn extract_response_data<T: serde::de::DeserializeOwned>(
.unwrap();

// FIXME: use the error code to return a proper error
match data.error.as_str() {
match data.detail.as_str() {
"Lightning invoice not paid yet." => {
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.error))
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.detail))
}
_ => Err(MokshaWalletError::MintError(data.error)),
_ => Err(MokshaWalletError::MintError(data.detail)),
}
}
}
Expand All @@ -182,11 +182,11 @@ async fn extract_response_data<T: serde::de::DeserializeOwned>(
.unwrap();

// FIXME: use the error code to return a proper error
match data.error.as_str() {
match data.detail.as_str() {
"Lightning invoice not paid yet." => {
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.error))
Err(MokshaWalletError::InvoiceNotPaidYet(data.code, data.detail))
}
_ => Err(MokshaWalletError::MintError(data.error)),
_ => Err(MokshaWalletError::MintError(data.detail)),
}
}
}
Expand All @@ -196,10 +196,10 @@ async fn extract_response_data<T: serde::de::DeserializeOwned>(
mod tests {
#[test]
fn test_deserialize_error() -> anyhow::Result<()> {
let input = "{\"code\":0,\"error\":\"Lightning invoice not paid yet.\"}";
let input = "{\"code\":0,\"detail\":\"Lightning invoice not paid yet.\"}";
let data = serde_json::from_str::<super::CashuErrorResponse>(input)?;
assert_eq!(data.code, 0);
assert_eq!(data.error, "Lightning invoice not paid yet.");
assert_eq!(data.detail, "Lightning invoice not paid yet.");
Ok(())
}
}

0 comments on commit e3c9475

Please sign in to comment.