use pcre2::Error as Pcre2Error;
use std::{fmt, io};
#[derive(Debug)]
pub enum BotDetectorError {
Io(io::Error),
JsonParse(serde_json::Error),
RegexCompile(Pcre2Error),
}
impl fmt::Display for BotDetectorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BotDetectorError::Io(e) => write!(f, "IO error: {e}"),
BotDetectorError::JsonParse(e) => write!(f, "JSON Parse error: {e}"),
BotDetectorError::RegexCompile(e) => write!(f, "Regex compilation error: {e}"),
}
}
}
impl From<io::Error> for BotDetectorError {
fn from(value: io::Error) -> Self {
BotDetectorError::Io(value)
}
}
impl From<serde_json::Error> for BotDetectorError {
fn from(value: serde_json::Error) -> Self {
BotDetectorError::JsonParse(value)
}
}
impl From<Pcre2Error> for BotDetectorError {
fn from(value: Pcre2Error) -> Self {
BotDetectorError::RegexCompile(value)
}
}
impl BotDetectorError {
#[must_use]
pub fn error_message(&self) -> String {
format!("{self}")
}
}