pub struct ErrorDetailsPolicy { /* private fields */ }Expand description
Which routes return details in their error bodies.
A global switch plus per-route overrides, checked in the order they were
added: the first whose pattern matches the route decides. A pattern is a
glob over the mounted route path, where * stays within one segment and
** spans segments; every path parameter counts as one segment, so
/v1/users/* matches the route /v1/users/{id}. Decided once per route
when the router is built, so a request pays nothing for it.
§Examples
use structured_proxy::transcode::error::ErrorDetailsPolicy;
// Details everywhere except the internal admin surface.
let policy = ErrorDetailsPolicy::default()
.route("/v1/admin/**", false)
.unwrap();
assert!(policy.enabled_for("/v1/users/{id}"));
assert!(!policy.enabled_for("/v1/admin/users/{id}"));
// Off by default, back on for one sub-route.
let policy = ErrorDetailsPolicy::disabled()
.route("/v1/public/**", true)
.unwrap();
assert!(!policy.enabled_for("/v1/users/{id}"));
assert!(policy.enabled_for("/v1/public/items"));
// The opaque-detail extension, off unless switched on, here for one route.
let policy = ErrorDetailsPolicy::default()
.opaque_route("/v1/partner/**", true)
.unwrap();
assert!(!policy.opaque_for("/v1/users/{id}"));
assert!(policy.opaque_for("/v1/partner/orders"));Implementations§
Source§impl ErrorDetailsPolicy
impl ErrorDetailsPolicy
Sourcepub fn route(self, pattern: &str, enabled: bool) -> Result<Self, String>
pub fn route(self, pattern: &str, enabled: bool) -> Result<Self, String>
Add an override for the routes pattern matches, checked after the
ones added before it.
§Errors
A pattern that does not start with / (it could never match a route)
or is not a valid glob.
Sourcepub fn with_opaque_details(self, enabled: bool) -> Self
pub fn with_opaque_details(self, enabled: bool) -> Self
Set, for every route without an override, whether a detail whose type
no descriptor describes goes to opaqueDetails (see
StatusDetails::with_opaque_details). Off by default: such bytes
cannot be checked for a nested DebugInfo.
Sourcepub fn enabled_for(&self, route_path: &str) -> bool
pub fn enabled_for(&self, route_path: &str) -> bool
Whether the route mounted at route_path (axum form, e.g.
/v1/users/{id}) returns details: the first matching rule that sets
it decides, otherwise the global switch.
Sourcepub fn opaque_for(&self, route_path: &str) -> bool
pub fn opaque_for(&self, route_path: &str) -> bool
Whether the route mounted at route_path forwards details of unknown
types in opaqueDetails: the first matching rule that sets it decides,
otherwise the global switch.
Trait Implementations§
Source§impl Clone for ErrorDetailsPolicy
impl Clone for ErrorDetailsPolicy
Source§impl Debug for ErrorDetailsPolicy
impl Debug for ErrorDetailsPolicy
Auto Trait Implementations§
impl Freeze for ErrorDetailsPolicy
impl RefUnwindSafe for ErrorDetailsPolicy
impl Send for ErrorDetailsPolicy
impl Sync for ErrorDetailsPolicy
impl Unpin for ErrorDetailsPolicy
impl UnsafeUnpin for ErrorDetailsPolicy
impl UnwindSafe for ErrorDetailsPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request