1use std::convert::From;
7
8use derive_more::{Display, Error};
9use validator::ValidationErrors;
10
11#[derive(Debug, PartialEq, Display, Clone, Error)]
13#[cfg(not(tarpaulin_include))]
14pub enum CredsError {
15 #[display(fmt = "the value you passed contains profainity")]
17 ProfainityError,
18
19 #[display(fmt = "username_case_mapped violation")]
23 UsernameCaseMappedError,
24
25 #[display(fmt = "contains blacklisted words")]
28 BlacklistError,
29
30 #[display(fmt = "The value passed in not an email")]
32 NotAnEmail,
33
34 #[display(fmt = "Password too short")]
36 PasswordTooShort,
37
38 #[display(fmt = "Password too long")]
40 PasswordTooLong,
41
42 #[display(fmt = "{}", _0)]
44 Argon2Error(argon2::Error),
45}
46
47impl From<argon2::Error> for CredsError {
48 fn from(e: argon2::Error) -> CredsError {
49 CredsError::Argon2Error(e)
50 }
51}
52
53impl From<ValidationErrors> for CredsError {
54 fn from(_: ValidationErrors) -> CredsError {
55 CredsError::NotAnEmail
56 }
57}
58
59pub type CredsResult<V> = std::result::Result<V, crate::errors::CredsError>;