use derive_more::{Display, Error};
#[cfg(feature = "full")]
use redis::RedisError;
#[cfg(feature = "full")]
use tokio::sync::oneshot::error::RecvError;
#[derive(Debug, PartialEq, Display, Error)]
#[cfg(not(tarpaulin_include))]
pub enum CaptchaError {
#[display(fmt = "LevelBuilder should have atleaset one level configured")]
LevelEmpty,
#[display(fmt = "difficulty factor must be greater than zero")]
DifficultyFactorZero,
#[display(fmt = "difficulty factor must be greater than zero")]
CaptchaDurationZero,
#[display(fmt = "Set difficulty factor")]
SetDifficultyFactor,
#[display(fmt = "Set visitor threshold")]
SetVisitorThreshold,
#[display(fmt = "Duplicate visitor count")]
DuplicateVisitorCount,
#[display(fmt = "Difficulty factor should increase with level")]
DecreaseingDifficultyFactor,
#[display(fmt = "Actor mailbox error")]
MailboxError,
#[display(fmt = "Insuffiencient Difficulty")]
InsuffiencientDifficulty,
#[display(fmt = "String now found")]
StringNotFound,
#[display(fmt = "PoW computed over configuration not intended for target sitekey")]
MCaptchaKeyValidationFail,
#[display(fmt = "Invalid PoW")]
InvalidPoW,
#[display(fmt = "Please set value: {}", _0)]
PleaseSetValue(#[error(not(source))] String),
#[display(fmt = "{}", _0)]
#[cfg(feature = "full")]
RedisError(RedisError),
#[display(fmt = "{}", _0)]
#[cfg(feature = "full")]
RecvError(RecvError),
#[display(
fmt = "Something weird happening with mCaptcha redis module. Please file bug report"
)]
MCaptchaRedisModuleError,
#[display(
fmt = "You are trying to connect to a Redis instance that doesn't have mCaptcha redis module loaded.
Please see https://github.com/mCaptcha/cache for details on how to install mCaptcha redis module moudle"
)]
MCaptchaRedisModuleIsNotLoaded,
#[display(
fmt = "The Redis instance that libmcaptcha is trying to connect to has mCaptcha Redis module loaded,
but it's probably outdated and as a result, we are not able to find all required commands to operate mCaptcha
Command {} is not found",
_0
)]
MCaptchaRediSModuleCommandNotFound(#[error(not(source))] String),
QueueFull,
}
#[cfg(feature = "full")]
#[cfg(not(tarpaulin_include))]
impl From<RedisError> for CaptchaError {
fn from(e: RedisError) -> Self {
Self::RedisError(e)
}
}
#[cfg(feature = "full")]
#[cfg(not(tarpaulin_include))]
impl From<RecvError> for CaptchaError {
fn from(e: RecvError) -> Self {
log::error!("{:?}", e);
Self::RecvError(e)
}
}
#[cfg(feature = "full")]
#[cfg(not(tarpaulin_include))]
impl From<actix::MailboxError> for CaptchaError {
fn from(_: actix::MailboxError) -> Self {
Self::MailboxError
}
}
pub type CaptchaResult<V> = std::result::Result<V, CaptchaError>;