Struct GrpcErrorsAsFailures

pub struct GrpcErrorsAsFailures { /* private fields */ }

Response classifier for gRPC responses.

gRPC doesn't use normal HTTP statuses for indicating success or failure but instead a special header that might appear in a trailer.

Responses are considered successful if

All others are considered failures.

Implementations

impl GrpcErrorsAsFailures

fn new() -> Self

Create a new GrpcErrorsAsFailures.

fn with_success(self, code: GrpcCode) -> Self

Change which gRPC codes are considered success.

Defaults to only considering Ok as success.

Ok will always be considered a success.

Example

Servers might not want to consider Invalid Argument or Not Found as failures since thats likely the clients fault:

use tower_http::classify::{GrpcErrorsAsFailures, GrpcCode};

let classifier = GrpcErrorsAsFailures::new()
    .with_success(GrpcCode::InvalidArgument)
    .with_success(GrpcCode::NotFound);
fn make_classifier() -> SharedClassifier<Self>

Returns a MakeClassifier that produces GrpcErrorsAsFailures.

This is a convenience function that simply calls SharedClassifier::new.

Trait Implementations

impl ClassifyResponse for GrpcErrorsAsFailures

type FailureClass = GrpcFailureClass;
type ClassifyEos = GrpcEosErrorsAsFailures;
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 GrpcErrorsAsFailures

fn clone(&self) -> GrpcErrorsAsFailures

impl Debug for GrpcErrorsAsFailures

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Default for GrpcErrorsAsFailures

fn default() -> Self

Auto Trait Implementations

impl Freeze for GrpcErrorsAsFailures

impl RefUnwindSafe for GrpcErrorsAsFailures

impl Send for GrpcErrorsAsFailures

impl Sync for GrpcErrorsAsFailures

impl Unpin for GrpcErrorsAsFailures

impl UnsafeUnpin for GrpcErrorsAsFailures

impl UnwindSafe for GrpcErrorsAsFailures

Blanket Implementations

impl<T> Any for GrpcErrorsAsFailures where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for GrpcErrorsAsFailures where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for GrpcErrorsAsFailures where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for GrpcErrorsAsFailures where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for GrpcErrorsAsFailures

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for GrpcErrorsAsFailures

impl<T> PolicyExt for GrpcErrorsAsFailures 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 GrpcErrorsAsFailures where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for GrpcErrorsAsFailures

impl<T, U> Into<U> for GrpcErrorsAsFailures where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for GrpcErrorsAsFailures 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 GrpcErrorsAsFailures where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>