chore: add app_errors
This commit is contained in:
parent
e5bcd91cc8
commit
468d911840
10
app_errors/.gitignore
vendored
Normal file
10
app_errors/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/target
|
||||
target
|
||||
Cargo.lock
|
||||
.cache
|
||||
.temp
|
||||
.env
|
||||
*.log
|
||||
.DS_Store
|
||||
logs
|
||||
tmp
|
17
app_errors/Cargo.toml
Normal file
17
app_errors/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "app_errors"
|
||||
version = "0.1.0"
|
||||
authors = ["JesusPerez <jpl@jesusperez.pro>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
error-chain = "0.12.4"
|
||||
failure = "0.1.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_derive = "1.0.125"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_derive = "1.0.125"
|
4
app_errors/README.md
Normal file
4
app_errors/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
### App Error library
|
||||
|
||||
Application Errors definition
|
||||
|
3
app_errors/TODO.md
Normal file
3
app_errors/TODO.md
Normal file
@ -0,0 +1,3 @@
|
||||
# App Errors library
|
||||
|
||||
- [ ] Collect errors and sync
|
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…
Reference in New Issue
Block a user