Make webhook handler more robust to API failures

This commit is contained in:
Olivier 'reivilibre' 2021-11-13 07:57:08 +00:00
parent 926519c908
commit dbf2e24369
1 changed files with 13 additions and 4 deletions

View File

@ -179,10 +179,19 @@ async fn monzo_hook(hook: MonzoHook, state: State) -> anyhow::Result<impl warp::
buf.push_str(&format!(" on {}", on_account_name));
if let Some(monzo_client) = monzo_client_freshened(&state).await? {
// include new balance
let new_bal = monzo_client.balance(&txn_created.account_id).await?.balance;
let now_quid = new_bal / 100;
let now_pennies = new_bal % 100;
buf.push_str(&format!(" now £{}.{:02}", now_quid, now_pennies));
match monzo_client.balance(&txn_created.account_id).await {
Ok(resp) => {
let new_bal = resp.balance;
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);