1use std::fmt;
2
3#[derive(Debug)]
4pub enum ApiKeyStorageError {
5 KeyNotFound,
6 KeyAlreadyExists,
7 SerializationError(String),
8 StorageError(String),
9}
10
11impl fmt::Display for ApiKeyStorageError {
12 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13 match self {
14 ApiKeyStorageError::KeyNotFound => write!(f, "Key not found"),
15 ApiKeyStorageError::KeyAlreadyExists => write!(f, "Key already exists"),
16 ApiKeyStorageError::SerializationError(e) => write!(f, "Serialization error: {}", e),
17 ApiKeyStorageError::StorageError(e) => write!(f, "Storage error: {}", e),
18 }
19 }
20}
21
22impl ApiKeyStorageError {
23 pub fn to_message_type(&self) -> String {
24 match self {
25 ApiKeyStorageError::KeyNotFound => "KeyNotFound".to_string(),
26 ApiKeyStorageError::KeyAlreadyExists => "KeyAlreadyExists".to_string(),
27 ApiKeyStorageError::SerializationError(_) => "SerializationError".to_string(),
28 ApiKeyStorageError::StorageError(_) => "StorageError".to_string(),
29 }
30 }
31}
32
33#[derive(Debug)]
34pub enum ApiKeyManagerError {
35 StorageError(ApiKeyStorageError),
36 LimiterError(ApiKeyLimiterError),
37 Other(String),
38}
39
40#[derive(Debug)]
41pub enum ApiKeyLimiterError {
42 RateLimitExceeded,
43 Other(String),
44}
45
46impl fmt::Display for ApiKeyLimiterError {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 match self {
49 ApiKeyLimiterError::RateLimitExceeded => write!(f, "Rate limit exceeded"),
50 ApiKeyLimiterError::Other(e) => write!(f, "Other error: {}", e),
51 }
52 }
53}
54
55impl ApiKeyLimiterError {
56 pub fn to_message_type(&self) -> String {
57 match self {
58 ApiKeyLimiterError::RateLimitExceeded => "RateLimitExceeded".to_string(),
59 ApiKeyLimiterError::Other(_) => "ApiLimiter::Other".to_string(),
60 }
61 }
62}