Refactored the whole code to a better structure
This commit is contained in:
parent
87cc8ac794
commit
12b865bf17
21 changed files with 473 additions and 257 deletions
33
project/src/errors.rs
Normal file
33
project/src/errors.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use bcrypt::BcryptError;
|
||||
use diesel::result;
|
||||
use std::fmt;
|
||||
|
||||
pub enum CustomError {
|
||||
HashError(BcryptError),
|
||||
DBError(result::Error),
|
||||
PasswordMatchError(String),
|
||||
PasswordWrong(String),
|
||||
}
|
||||
|
||||
impl From<BcryptError> for CustomError {
|
||||
fn from(error: BcryptError) -> Self {
|
||||
CustomError::HashError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<result::Error> for CustomError {
|
||||
fn from(error: result::Error) -> Self {
|
||||
CustomError::DBError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CustomError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
CustomError::HashError(error) => write!(f, "{}", error),
|
||||
CustomError::DBError(error) => write!(f, "{}", error),
|
||||
CustomError::PasswordMatchError(error) => write!(f, "{}", error),
|
||||
CustomError::PasswordWrong(error) => write!(f, "{}", error),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue