Skip to main content

pas_external/
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    /// Any sdk-core primitive surfaced an error (e.g.
41    /// [`ppoppo_sdk_core::SdkCoreError::InvalidPpnum`] from
42    /// [`crate::types::Ppnum::try_from`]). Phase A introduced sdk-core as
43    /// the home for SDK-shared primitives; pas-external aggregates
44    /// sdk-core errors at this seam so existing consumer-side code paths
45    /// reaching `Result<_, pas_external::Error>` keep compiling.
46    #[error("sdk-core: {0}")]
47    SdkCore(#[from] ::ppoppo_sdk_core::SdkCoreError),
48    #[cfg(feature = "oauth")]
49    #[error("Invalid URL: {0}")]
50    InvalidUrl(#[from] url::ParseError),
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56    use static_assertions::assert_impl_all;
57
58    assert_impl_all!(Error: Send, Sync);
59    assert_impl_all!(TokenError: Send, Sync);
60}