tower_rate_limiter/limiter/
error.rs1use std::time::Duration;
4
5#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
7pub enum RateLimitError {
8 #[error("client key unavailable ({0}): {1}")]
10 Key(String, String),
11 #[error("rate-limit quota unavailable ({0}): {1}")]
13 Quota(String, String),
14 #[error("rate-limit store unavailable ({0}): {1}")]
16 Store(String, String),
17}
18
19impl RateLimitError {
20 pub fn code(&self) -> &str {
22 match self {
23 Self::Key(code, _) | Self::Quota(code, _) | Self::Store(code, _) => code,
24 }
25 }
26}
27
28#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
30pub enum ConfigError {
31 #[error("rate-limit window {0:?} is shorter than the minimum {1:?}")]
33 WindowTooShort(Duration, Duration),
34 #[error("empty policy name")]
36 EmptyPolicyName,
37}