Skip to main content

pas_client/
error.rs

1#[derive(Debug, thiserror::Error)]
2#[non_exhaustive]
3pub enum TokenError {
4    #[error("invalid token format")]
5    InvalidFormat,
6    #[error("verification failed: {0}")]
7    VerificationFailed(String),
8    #[error("{claim}: expected '{expected}', got '{actual}'")]
9    ClaimMismatch {
10        claim: &'static str,
11        expected: String,
12        actual: String,
13    },
14    #[error("missing claim: {0}")]
15    MissingClaim(&'static str),
16    #[error("missing payload")]
17    MissingPayload,
18    #[error("invalid footer")]
19    InvalidFooter,
20    #[error("missing footer")]
21    MissingFooter,
22    #[error("token expired")]
23    Expired,
24}
25
26#[derive(Debug, thiserror::Error)]
27#[non_exhaustive]
28pub enum Error {
29    #[error("OAuth2 {operation} failed (status={status:?}): {detail}")]
30    OAuth {
31        operation: &'static str,
32        status: Option<u16>,
33        detail: String,
34    },
35    #[cfg(feature = "oauth")]
36    #[error("HTTP error: {0}")]
37    Http(#[from] reqwest::Error),
38    #[error("token error: {0}")]
39    Token(#[from] TokenError),
40    #[error("Invalid ppnum: {0}")]
41    InvalidPpnum(String),
42    #[cfg(feature = "oauth")]
43    #[error("Invalid URL: {0}")]
44    InvalidUrl(#[from] url::ParseError),
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50    use static_assertions::assert_impl_all;
51
52    assert_impl_all!(Error: Send, Sync);
53    assert_impl_all!(TokenError: Send, Sync);
54}