Skip to main content

serenade_rate_limiter/
error.rs

1//! [`RateLimiterError`] variants.
2
3/// Failure while creating or consuming a rate limiter.
4#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
5pub enum RateLimiterError {
6    /// Limiter or subject key is empty or otherwise invalid.
7    #[error("invalid rate-limiter key `{key}`: {message}")]
8    InvalidKey {
9        /// Key that failed validation.
10        key: String,
11        /// Reason text.
12        message: String,
13    },
14    /// Token count was zero when a positive consume was required, or overflowed.
15    #[error("invalid token count `{tokens}`: {message}")]
16    InvalidTokens {
17        /// Requested token count.
18        tokens: u32,
19        /// Reason text.
20        message: String,
21    },
22    /// Underlying storage failure.
23    #[error("rate-limiter storage error: {message}")]
24    Storage {
25        /// Reason text.
26        message: String,
27    },
28}