webgates_sessions/
errors.rs1use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, SessionError>;
10
11#[derive(Debug, Error, Clone, PartialEq, Eq)]
13pub enum SessionError {
14 #[error(transparent)]
16 Config(#[from] ConfigError),
17
18 #[error(transparent)]
20 Token(#[from] TokenError),
21
22 #[error(transparent)]
24 Renewal(#[from] RenewalError),
25
26 #[error(transparent)]
28 Repository(#[from] RepositoryError),
29
30 #[error(transparent)]
32 Revocation(#[from] RevocationError),
33
34 #[error("{message}")]
36 Unimplemented {
37 message: String,
39 },
40}
41
42impl SessionError {
43 pub fn unimplemented(message: impl Into<String>) -> Self {
45 Self::Unimplemented {
46 message: message.into(),
47 }
48 }
49}
50
51#[derive(Debug, Error, Clone, PartialEq, Eq)]
53pub enum ConfigError {
54 #[error("invalid session configuration")]
56 Invalid,
57}
58
59#[derive(Debug, Error, Clone, PartialEq, Eq)]
61pub enum TokenError {
62 #[error("failed to generate token material")]
64 GenerationFailed,
65
66 #[error("failed to hash token material")]
68 HashFailed,
69
70 #[error("failed to issue auth token")]
72 AuthIssuanceFailed,
73
74 #[error("invalid token material")]
76 InvalidTokenMaterial,
77
78 #[error("invalid refresh token length")]
80 InvalidRefreshTokenLength,
81
82 #[error("token operation failed")]
84 Failed,
85}
86
87#[derive(Debug, Error, Clone, PartialEq, Eq)]
89pub enum RenewalError {
90 #[error("session is not eligible for renewal")]
92 NotEligible,
93
94 #[error("renewal lease unavailable")]
96 LeaseUnavailable,
97
98 #[error("refresh token replay detected")]
100 ReplayDetected,
101
102 #[error("session rotation failed")]
104 RotationFailed,
105}
106
107#[derive(Debug, Error, Clone, PartialEq, Eq)]
109pub enum RepositoryError {
110 #[error("session not found")]
112 SessionNotFound,
113
114 #[error("session family not found")]
116 SessionFamilyNotFound,
117
118 #[error("concurrent session update detected")]
120 Conflict,
121
122 #[error("invalid persisted session state")]
124 InvalidState,
125
126 #[error("{message}")]
128 Backend {
129 message: String,
131 },
132}
133
134impl RepositoryError {
135 pub fn backend(message: impl Into<String>) -> Self {
137 Self::Backend {
138 message: message.into(),
139 }
140 }
141}
142
143impl From<crate::repository::RepositoryError> for RepositoryError {
144 fn from(value: crate::repository::RepositoryError) -> Self {
145 match value {
146 crate::repository::RepositoryError::SessionNotFound => Self::SessionNotFound,
147 crate::repository::RepositoryError::SessionFamilyNotFound => {
148 Self::SessionFamilyNotFound
149 }
150 crate::repository::RepositoryError::Conflict => Self::Conflict,
151 crate::repository::RepositoryError::InvalidState => Self::InvalidState,
152 crate::repository::RepositoryError::Backend { message } => Self::Backend { message },
153 }
154 }
155}
156
157impl From<crate::repository::RepositoryError> for SessionError {
158 fn from(value: crate::repository::RepositoryError) -> Self {
159 Self::Repository(value.into())
160 }
161}
162
163#[derive(Debug, Error, Clone, PartialEq, Eq)]
165pub enum RevocationError {
166 #[error("cannot revoke missing session")]
168 SessionNotFound,
169
170 #[error("cannot revoke missing session family")]
172 SessionFamilyNotFound,
173
174 #[error("revocation failed")]
176 Failed,
177}