Struct StatusInRangeAsFailures
pub struct StatusInRangeAsFailures { /* private fields */ }
Response classifier that considers responses with a status code within some range to be failures.
Example
A client with tracing where server errors and client errors are considered failures.
use tower_http::{trace::TraceLayer, classify::StatusInRangeAsFailures};
use tower::{ServiceBuilder, Service, ServiceExt};
use http::{Request, Method};
use http_body_util::Full;
use bytes::Bytes;
use hyper_util::{rt::TokioExecutor, client::legacy::Client};
# async fn foo() -> Result<(), tower::BoxError> {
let classifier = StatusInRangeAsFailures::new(400..=599);
let client = Client::builder(TokioExecutor::new()).build_http();
let mut client = ServiceBuilder::new()
.layer(TraceLayer::new(classifier.into_make_classifier()))
.service(client);
let request = Request::builder()
.method(Method::GET)
.uri("https://example.com")
.body(Full::<Bytes>::default())
.unwrap();
let response = client.ready().await?.call(request).await?;
# Ok(())
# }
Implementations
impl StatusInRangeAsFailures
fn new(range: RangeInclusive<u16>) -> SelfCreates a new
StatusInRangeAsFailures.Panics
Panics if the start or end of
rangearen't valid status codes as determined byStatusCode::from_u16.fn new_for_client_and_server_errors() -> SelfCreates a new
StatusInRangeAsFailuresthat classifies client and server responses as failures.This is a convenience for
StatusInRangeAsFailures::new(400..=599).fn into_make_classifier(self) -> SharedClassifier<Self>Convert this
StatusInRangeAsFailuresinto aMakeClassifier.
Trait Implementations
impl ClassifyResponse for StatusInRangeAsFailures
type FailureClass = StatusInRangeFailureClass;type ClassifyEos = NeverClassifyEos<<StatusInRangeAsFailures as ClassifyResponse>::FailureClass>;fn classify_response<B>(self, res: &Response<B>) -> ClassifiedResponse<Self::FailureClass, Self::ClassifyEos>fn classify_error<E>(self, error: &E) -> Self::FailureClass where E: Display + 'static,
impl Clone for StatusInRangeAsFailures
fn clone(&self) -> StatusInRangeAsFailures
impl Debug for StatusInRangeAsFailures
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl Freeze for StatusInRangeAsFailures
impl RefUnwindSafe for StatusInRangeAsFailures
impl Send for StatusInRangeAsFailures
impl Sync for StatusInRangeAsFailures
impl Unpin for StatusInRangeAsFailures
impl UnsafeUnpin for StatusInRangeAsFailures
impl UnwindSafe for StatusInRangeAsFailures
Blanket Implementations
impl<T> Any for StatusInRangeAsFailures
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for StatusInRangeAsFailures
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for StatusInRangeAsFailures
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for StatusInRangeAsFailures
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for StatusInRangeAsFailures
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for StatusInRangeAsFailures
impl<T> PolicyExt for StatusInRangeAsFailures
where
T: ?Sized,
fn and<P, B, E>(self, other: P) -> And<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,fn or<P, B, E>(self, other: P) -> Or<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,
impl<T> ToOwned for StatusInRangeAsFailures
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> WithSubscriber for StatusInRangeAsFailures
impl<T, U> Into<U> for StatusInRangeAsFailures
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for StatusInRangeAsFailures
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for StatusInRangeAsFailures
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>