diff --git a/src/account.rs b/src/account.rs index 26de0d0..08778b3 100644 --- a/src/account.rs +++ b/src/account.rs @@ -83,7 +83,7 @@ impl Account { if !is_valid_amount(amount) { Err(InvalidTransaction("withdrawal amount must be a positive number".into())) } else if amount > self.available { - Err(FailedTransaction("withdrawal failed: insufficient funds".into())) + Err(FailedTransaction("withdrawal failed because of insufficient funds".into())) } else { self.available -= amount; self.total -= amount; diff --git a/src/account_activity.rs b/src/account_activity.rs index ab0f225..63d7b47 100644 --- a/src/account_activity.rs +++ b/src/account_activity.rs @@ -1,6 +1,7 @@ use crate::dispute::DisputeCase; use crate::transaction::{Transaction, TransactionID}; use crate::ClientID; +use std::fmt::{Display, Formatter}; use thiserror::Error; #[derive(Error, Debug)] @@ -117,3 +118,16 @@ impl AccountActivity { } } } + +impl Display for AccountActivity { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let kind = match self { + AccountActivity::Deposit(_) => "deposit", + AccountActivity::Withdrawal(_) => "withdrawal", + AccountActivity::Dispute(_) => "dispute", + AccountActivity::Resolve(_) => "resolve", + AccountActivity::Chargeback(_) => "chargeback", + }; + write!(f, "{}", kind) + } +} diff --git a/src/processor.rs b/src/processor.rs index 3523ba2..24942a9 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -23,15 +23,17 @@ pub trait Processor { Err(err) => { error!(error = ?err, "error parsing account activity record") } - Ok(transaction) => { + Ok(activity) => { let account = accounts - .entry(transaction.client_id()) - .or_insert_with(|| Account::new(transaction.client_id())); - if let Err(err) = account.transaction(transaction) { + .entry(activity.client_id()) + .or_insert_with(|| Account::new(activity.client_id())); + if let Err(err) = account.transaction(activity) { warn!( - transaction.id = %transaction.transaction_id(), - client.id = %transaction.client_id(), - "error processing account activity: {}",err + activity = %activity, + transaction.id = %activity.transaction_id(), + client.id = %activity.client_id(), + error = ?err, + "error processing account activity", ); } }