geronimo_captcha/
error.rs1use std::fmt;
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, CaptchaError>;
5
6#[derive(Error, Debug)]
7pub enum CaptchaError {
8 #[error("invalid input: {0}")]
9 InvalidInput(String),
10 #[error("decode image")]
11 Decode(#[source] image::ImageError),
12 #[error("encode image")]
13 Encode(#[source] image::ImageError),
14 #[error("registry error: {0}")]
15 Registry(#[from] RegistryRejection),
16 #[error("system clock is before the unix epoch")]
17 Clock,
18 #[error("internal error: {0}")]
19 Internal(String),
20}
21
22#[derive(Clone, Copy, PartialEq, Eq, Debug)]
23pub enum RegistryRejection {
24 AlreadyVerified,
25 NotRegistered,
26 MaxAttemptsLimitExceeded,
27 AtCapacity,
28}
29
30impl fmt::Display for RegistryRejection {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 f.write_str(match self {
33 Self::AlreadyVerified => "ALREADY_VERIFIED",
34 Self::NotRegistered => "NOT_REGISTERED",
35 Self::MaxAttemptsLimitExceeded => "MAX_ATTEMPTS_LIMIT_EXCEEDED",
36 Self::AtCapacity => "AT_CAPACITY",
37 })
38 }
39}
40
41impl std::error::Error for RegistryRejection {}