Make webhook handler more robust to API failures
This commit is contained in:
parent
926519c908
commit
dbf2e24369
17
src/web.rs
17
src/web.rs
@ -179,10 +179,19 @@ async fn monzo_hook(hook: MonzoHook, state: State) -> anyhow::Result<impl warp::
|
|||||||
buf.push_str(&format!(" on {}", on_account_name));
|
buf.push_str(&format!(" on {}", on_account_name));
|
||||||
if let Some(monzo_client) = monzo_client_freshened(&state).await? {
|
if let Some(monzo_client) = monzo_client_freshened(&state).await? {
|
||||||
// include new balance
|
// include new balance
|
||||||
let new_bal = monzo_client.balance(&txn_created.account_id).await?.balance;
|
match monzo_client.balance(&txn_created.account_id).await {
|
||||||
let now_quid = new_bal / 100;
|
Ok(resp) => {
|
||||||
let now_pennies = new_bal % 100;
|
let new_bal = resp.balance;
|
||||||
buf.push_str(&format!(" now £{}.{:02}", now_quid, now_pennies));
|
let now_quid = new_bal / 100;
|
||||||
|
let now_pennies = new_bal % 100;
|
||||||
|
buf.push_str(&format!(" now £{}.{:02}", now_quid, now_pennies));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
buf.push_str(". Error when getting now.");
|
||||||
|
eprintln!("when querying balance after webhook: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = MessageEventContent::text_plain(&buf);
|
let content = MessageEventContent::text_plain(&buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user