chore: add app_errors
This commit is contained in:
parent
e5bcd91cc8
commit
468d911840
5 changed files with 122 additions and 0 deletions
88
app_errors/src/lib.rs
Normal file
88
app_errors/src/lib.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/// Main errors definition
|
||||
//
|
||||
// Copyright 2021, Jesús Pérez Lorenzo
|
||||
//
|
||||
use failure::Fail;
|
||||
use std::fmt;
|
||||
use serde::{Serialize};
|
||||
|
||||
///`AppError` Aplication Errors definition ans display
|
||||
///
|
||||
#[derive(Debug)]
|
||||
pub enum AppError {
|
||||
/// when toke not valid
|
||||
NoValidToken,
|
||||
NoValidSession,
|
||||
SSLModeError,
|
||||
RunningModeError,
|
||||
UndefinedCollection,
|
||||
RecordAlreadyExists,
|
||||
RecordNotFound,
|
||||
DatabaseError,
|
||||
NoDataStorePool,
|
||||
NoAppEnvLoaded,
|
||||
NoCertsLoaded,
|
||||
SqlDeleteError,
|
||||
HasherError,
|
||||
MailError,
|
||||
OperationCanceled,
|
||||
ErrorInternalServerError(String),
|
||||
}
|
||||
|
||||
#[allow(clippy::pattern_type_mismatch)]
|
||||
impl fmt::Display for AppError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
AppError::NoValidToken => write!(f, "No valid token found"),
|
||||
AppError::NoValidSession => write!(f, "No valid session found"),
|
||||
AppError::SSLModeError => write!(f, "SSL Mode error"),
|
||||
AppError::RunningModeError => write!(f, "No valid run mode"),
|
||||
AppError::UndefinedCollection => write!(f, "Collection undefined"),
|
||||
AppError::RecordAlreadyExists => write!(f, "This record violates a unique constraint"),
|
||||
AppError::RecordNotFound => write!(f, "This record does not exist"),
|
||||
AppError::NoDataStorePool => write!(f, "No data store pool"),
|
||||
AppError::NoAppEnvLoaded => write!(f, "Application environment not loaded.\nReview APP_CONFIG_PATH and config.toml content "),
|
||||
AppError::NoCertsLoaded => write!(f, "Certifcations not loaded. Review APP_CONFIG_PATH certs_store_path"),
|
||||
AppError::SqlDeleteError => write!(f, "Sql Delete error"),
|
||||
AppError::MailError => write!(f, "Mail error "),
|
||||
AppError::DatabaseError => write!(f, "Database error "),
|
||||
AppError::HasherError => write!(f, "Hasher error "),
|
||||
AppError::OperationCanceled => write!(f, "The running operation was canceled"),
|
||||
AppError::ErrorInternalServerError(e) => write!(f, "Invalid server error {:?}",e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ErrorResponse {
|
||||
err: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum AppCertificateError {
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
BadFile(String, String),
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
FileReadError(String, String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum LoginFailed {
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
MissingPassword(String, String),
|
||||
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
InvalidPassword(String, String),
|
||||
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
InvalidTokenOwner(String, String),
|
||||
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
PasswordHashingFailed(String, String),
|
||||
|
||||
#[fail(display = "{} - Reason: {}", 0, 1)]
|
||||
PasswordVerificationFailed(String, String),
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue