Skip to main content

securitydept_token_set_context/access_token_substrate/forwarder/
error.rs

1use securitydept_utils::error::{ErrorPresentation, ToErrorPresentation, UserRecovery};
2use snafu::Snafu;
3
4use super::super::TokenPropagatorError;
5
6/// Error type for propagation forwarders.
7///
8/// This type is framework-agnostic; concrete forwarder implementations
9/// (e.g. `AxumReverseProxyPropagationForwarder`) use it as their error variant.
10#[derive(Debug, Snafu)]
11pub enum PropagationForwarderError {
12    #[snafu(display("propagation forwarder is misconfigured: {message}"))]
13    Config { message: String },
14    #[snafu(display("token propagation failed: {source}"), context(false))]
15    TokenPropagator { source: TokenPropagatorError },
16    #[snafu(display("resolved propagation target origin is invalid: {source}"))]
17    InvalidOrigin { source: url::ParseError },
18}
19
20pub type PropagationForwarderResult<T> = Result<T, PropagationForwarderError>;
21
22impl ToErrorPresentation for PropagationForwarderError {
23    fn to_error_presentation(&self) -> ErrorPresentation {
24        match self {
25            Self::Config { .. } => ErrorPresentation::new(
26                "propagation_forwarder_config_invalid",
27                "The propagation forwarder is misconfigured.",
28                UserRecovery::ContactSupport,
29            ),
30            Self::TokenPropagator { source } => source.to_error_presentation(),
31            Self::InvalidOrigin { .. } => ErrorPresentation::new(
32                "propagation_forwarder_invalid_origin",
33                "The propagation target URL is invalid.",
34                UserRecovery::ContactSupport,
35            ),
36        }
37    }
38}