rocket_recaptcha_v3/
errors.rs

1use std::{
2    error::Error,
3    fmt::{Display, Error as FmtError, Formatter},
4};
5
6#[derive(Debug, Clone)]
7/// Errors of the `ReCaptcha` struct.
8pub enum ReCaptchaError {
9    /// The secret key is invalid.
10    InvalidInputSecret,
11    /// The reCAPTCHA token is invalid.
12    InvalidReCaptchaToken,
13    /// The reCAPTCHA token is no longer valid.
14    TimeoutOrDuplicate,
15    /// Errors caused by internal malfunctions.
16    InternalError(String),
17}
18
19impl Display for ReCaptchaError {
20    #[inline]
21    fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
22        match self {
23            ReCaptchaError::InvalidInputSecret => f.write_str("The secret key is invalid."),
24            ReCaptchaError::InvalidReCaptchaToken => f.write_str("The reCAPTCHA token is invalid."),
25            ReCaptchaError::TimeoutOrDuplicate => {
26                f.write_str("The reCAPTCHA token is no longer valid.")
27            },
28            ReCaptchaError::InternalError(text) => f.write_str(text),
29        }
30    }
31}
32
33impl Error for ReCaptchaError {}