Skip to main content

altcha_lib/
error.rs

1#[derive(Debug, thiserror::Error)]
2pub enum Error {
3    #[cfg(feature = "json")]
4    #[error("JSON parsing error: {0}")]
5    ParseJson(serde_json::Error),
6    #[error("Integer parsing error: {0}")]
7    ParseInteger(std::num::ParseIntError),
8    #[error("Expiration parsing error: {0}")]
9    ParseExpire(String),
10    #[error("Solution expired: {0}")]
11    VerificationFailedExpired(String),
12    #[error("Solution does not match the challenge: {0}")]
13    VerificationMismatchChallenge(String),
14    #[error("Signature in the solution does not match the challenge: {0}")]
15    VerificationMismatchSignature(String),
16    #[error("Max number reached: {0}")]
17    SolveChallengeMaxNumberReached(String),
18    #[error("Wrong challenge input: {0}")]
19    WrongChallengeInput(String),
20    #[error("Altcha error: {0}")]
21    General(String),
22    #[error("Error in the randomizer: {0}")]
23    RandError(rand::distr::uniform::Error),
24}
25
26impl From<rand::distr::uniform::Error> for Error {
27    fn from(value: rand::distr::uniform::Error) -> Self {
28        Error::RandError(value)
29    }
30}
31
32#[cfg(feature = "json")]
33impl From<serde_json::Error> for Error {
34    fn from(other: serde_json::Error) -> Self {
35        Self::ParseJson(other)
36    }
37}
38
39impl From<std::num::ParseIntError> for Error {
40    fn from(other: std::num::ParseIntError) -> Self {
41        Self::ParseInteger(other)
42    }
43}