Implement the http variant of the bank server.
During that process, many shortcomings with the socket server and the bank lib were fixed. I am aware a massive commit like this is not ideal.
This commit is contained in:
parent
c69654a924
commit
dac95b7dae
34 changed files with 1797 additions and 140 deletions
35
socket-server/src/commands/error.rs
Normal file
35
socket-server/src/commands/error.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
use std::ops::Deref;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use bank::account::AccountError;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub struct SocketAccountError(pub AccountError);
|
||||
|
||||
impl Display for SocketAccountError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.deref())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SocketAccountError {
|
||||
type Target = AccountError;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SocketAccountError> for u8 {
|
||||
fn from(e: SocketAccountError) -> Self {
|
||||
match e.deref() {
|
||||
AccountError::Overdraw => 11,
|
||||
AccountError::Inactive => 12,
|
||||
AccountError::InvalidAmount => 13,
|
||||
AccountError::NotFound => 14,
|
||||
AccountError::AccountNotZero => 15,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue