Skip to content

Commit a287f13

Browse files
authored
Add error handler (#378)
Now we anyway return empty quote - even if mint still didn't produce it.
1 parent f18f060 commit a287f13

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/external/mint.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::util::base58_decode;
55
use crate::web::data::RequestToMintBitcreditBillPayload;
66
use crate::CONFIG;
77
use borsh::{to_vec, BorshDeserialize};
8+
use log::error;
89
use moksha_core::primitives::CheckBitcreditQuoteResponse;
910
use moksha_core::primitives::{
1011
BillKeys, CurrencyUnit, PaymentMethod, PostMintQuoteBitcreditResponse,
@@ -49,10 +50,15 @@ pub async fn accept_mint_bitcredit(
4950
req.await.unwrap()
5051
}
5152

52-
// Usage of tokio::main to spawn a new runtime is necessary here, because Wallet is'nt Send - but
53+
// Usage of tokio::main to spawn a new runtime is necessary here, because Wallet isn't Send - but
5354
// this logic will be replaced soon
5455
#[tokio::main]
55-
pub async fn check_bitcredit_quote(bill_id_hex: &str, node_id: &str, bill_id_base58: String) {
56+
pub async fn check_bitcredit_quote(
57+
bill_id_hex: &str,
58+
node_id: &str,
59+
bill_id_base58: String,
60+
quote: BitcreditEbillQuote,
61+
) {
5662
let dir = PathBuf::from("./data/wallet".to_string());
5763
let db_path = dir.join("wallet.db").to_str().unwrap().to_string();
5864
let localstore = SqliteLocalStore::with_path(db_path.clone())
@@ -71,7 +77,13 @@ pub async fn check_bitcredit_quote(bill_id_hex: &str, node_id: &str, bill_id_bas
7177
.check_bitcredit_quote(&mint_url, bill_id_hex.to_owned(), node_id.to_owned())
7278
.await;
7379

74-
let quote = result.unwrap();
80+
let quote = result.unwrap_or_else(|e| {
81+
error!("{}", e);
82+
CheckBitcreditQuoteResponse {
83+
quote: quote.quote_id,
84+
amount: quote.sum,
85+
}
86+
});
7587

7688
if !quote.quote.is_empty() {
7789
add_bitcredit_quote_and_amount_in_quotes_map(quote.clone(), bill_id_base58);

src/web/handlers/bill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ pub async fn issue_bill(
363363

364364
if bill_payload.drawee == bill_payload.payee {
365365
return Err(service::Error::Validation(String::from(
366-
"Drawer can't be Payee at the same time",
366+
"Drawee can't be Payee at the same time",
367367
)));
368368
}
369369

src/web/handlers/quotes.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ pub async fn return_quote(
2828
if !quote.bill_id.is_empty() && quote.quote_id.is_empty() {
2929
// Usage of thread::spawn is necessary here, because we spawn a new tokio runtime in the
3030
// thread, but this logic will be replaced soon
31-
thread::spawn(move || check_bitcredit_quote(&copy_id_hex, &local_node_id, copy_id_base58))
32-
.join()
33-
.expect("Thread panicked");
31+
thread::spawn(move || {
32+
check_bitcredit_quote(&copy_id_hex, &local_node_id, copy_id_base58, quote.clone())
33+
})
34+
.join()
35+
.expect("Thread panicked");
3436
}
3537
quote = get_quote_from_map(&id).ok_or(Error::NotFound)?;
3638
Ok(Json(quote))

0 commit comments

Comments
 (0)