Skip to main content

ExposurePolicy

Trait ExposurePolicy 

Source
pub trait ExposurePolicy {
    // Provided methods
    fn http_status(&self, _identity: &ErrorIdentity) -> u16 { ... }
    fn visibility(&self, _identity: &ErrorIdentity) -> Visibility { ... }
    fn default_hints(
        &self,
        _identity: &ErrorIdentity,
    ) -> &'static [&'static str] { ... }
    fn retryable(&self, _identity: &ErrorIdentity) -> bool { ... }
    fn decide(&self, identity: &ErrorIdentity) -> ExposureDecision { ... }
}
Expand description

Policy that maps an error identity to protocol-level exposure decisions.

Implement this to control HTTP status codes, visibility, hints, and retryability per error identity.

§Example

use orion_error::protocol::{ExposurePolicy, Visibility};
use orion_error::ErrorIdentity;

struct MyPolicy;

impl ExposurePolicy for MyPolicy {
    fn http_status(&self, identity: &ErrorIdentity) -> u16 {
        match identity.code.as_str() {
            "biz.not_found" => 404,
            _ => 500,
        }
    }
}

All methods have defaults — override only what you need.

§Common override patterns

MethodOverride frequencyTypical use
http_statusMost commonMap error identity to HTTP status code
visibilityCommonControl which errors expose detail publicly
retryableOccasionalMark transient errors as retryable
default_hintsRareProvide user-facing recovery hints
decideRareOverride the entire composition logic

Most implementations only override http_status and optionally visibility. The rest can be left at their defaults.

Provided Methods§

Source

fn http_status(&self, _identity: &ErrorIdentity) -> u16

Source

fn visibility(&self, _identity: &ErrorIdentity) -> Visibility

Source

fn default_hints(&self, _identity: &ErrorIdentity) -> &'static [&'static str]

Source

fn retryable(&self, _identity: &ErrorIdentity) -> bool

Source

fn decide(&self, identity: &ErrorIdentity) -> ExposureDecision

Implementors§