Trait tower_http::classify::ClassifyResponse[][src]

pub trait ClassifyResponse {
    type FailureClass;
    type ClassifyEos: ClassifyEos<FailureClass = Self::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
; }
Expand description

Trait for classifying responses as either success or failure. Designed to support both unary requests (single request for a single response) as well as streaming responses.

Response classifiers are used in cases where middleware needs to determine whether a response completed successfully or failed. For example, they may be used by logging or metrics middleware to record failures differently from successes.

Furthermore, when a response fails, a response classifier may provide additional information about the failure. This can, for example, be used to build retry policies by indicating whether or not a particular failure is retryable.

Associated Types

type FailureClass[src]

The type returned when a response is classified as a failure.

Depending on the classifier, this may simply indicate that the request failed, or it may contain additional information about the failure, such as whether or not it is retryable.

type ClassifyEos: ClassifyEos<FailureClass = Self::FailureClass>[src]

The type used to classify the response end of stream (EOS).

Required methods

fn classify_response<B>(
    self,
    res: &Response<B>
) -> ClassifiedResponse<Self::FailureClass, Self::ClassifyEos>
[src]

Attempt to classify the beginning of a response.

In some cases, the response can be classified immediately, without waiting for a body to complete. This may include:

  • When the response has an error status code.
  • When a successful response does not have a streaming body.
  • When the classifier does not care about streaming bodies.

When the response can be classified immediately, classify_response returns a ClassifiedResponse::Ready which indicates whether the response succeeded or failed.

In other cases, however, the classifier may need to wait until the response body stream completes before it can classify the response. For example, gRPC indicates RPC failures using the grpc-status trailer. In this case, classify_response returns a ClassifiedResponse::RequiresEos containing a type which will be used to classify the response when the body stream ends.

fn classify_error<E>(self, error: &E) -> Self::FailureClass where
    E: Display + 'static, 
[src]

Classify an error.

Errors are always errors (doh) but sometimes it might be useful to have multiple classes of errors. A retry policy might allow retrying some errors and not others.

Implementors