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) -> Self
impl Debug for StatusInRangeAsFailures
fn fmt(&self, f: &mut Formatter<'_>) -> Result