1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Authentication error types.
use thiserror::Error;
/// Errors that can occur during authentication.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum AuthError {
/// Invalid credentials provided.
#[error("invalid credentials: {0}")]
InvalidCredentials(String),
/// Authentication failed on server.
#[error("authentication failed: {0}")]
AuthenticationFailed(String),
/// Token expired or invalid.
#[error("token expired or invalid")]
TokenExpired,
/// Token acquisition failed.
#[error("failed to acquire token: {0}")]
TokenAcquisition(String),
/// Unsupported authentication method.
#[error("unsupported authentication method: {0}")]
UnsupportedMethod(String),
/// SSPI/GSSAPI error.
#[error("SSPI error: {0}")]
Sspi(String),
/// Certificate error.
#[error("certificate error: {0}")]
Certificate(String),
/// Network error during authentication.
#[error("network error: {0}")]
Network(String),
/// Configuration error.
#[error("configuration error: {0}")]
Configuration(String),
/// Azure identity error.
#[error("Azure identity error: {0}")]
AzureIdentity(String),
}
impl AuthError {
/// Check if this error is transient and may succeed on retry.
///
/// Network errors, token acquisition failures (may be temporary service
/// issues), and Azure identity errors are potentially transient. Invalid
/// credentials and unsupported methods are terminal.
#[must_use]
pub fn is_transient(&self) -> bool {
matches!(
self,
Self::Network(_) | Self::TokenAcquisition(_) | Self::AzureIdentity(_)
)
}
/// Check if this error is terminal and will never succeed on retry.
///
/// Invalid credentials, unsupported methods, certificate errors, and
/// configuration errors are permanent.
#[must_use]
pub fn is_terminal(&self) -> bool {
matches!(
self,
Self::InvalidCredentials(_)
| Self::UnsupportedMethod(_)
| Self::Certificate(_)
| Self::Configuration(_)
)
}
}