Trait tourniquet::Next[][src]

pub trait Next {
    fn is_next(&self) -> bool;
}
Expand description

Trait indicating wether an error mandates trying the next service.

It is returned by the round-robin handler or the connector, and indicates wether we should try the next service, or if it should abort and bubble up the error to the caller.

A next error mandates trying the next service in the line. It is an error that could be solved by trying another server. This includes IO errors, server-side errors, etc. On the other hand, business errors should not be a next error since another server will most likely yield the same error (resource not found, permission denied, …).

Basically, a server that yields a Next error should be considered unhealthy.

Example

enum MyError {
    NotFound,
    PermissionDenied,
    InternalError,
    Timeout,
}

impl Next for MyError {
    fn is_next(&self) -> bool {
        match self {
            // Business logic error, that are likely to happen on all servers
            Self::NotFound | Self::PermissionDenied => false,
            // Server specific error: server software down, host down, etc. Try the next one
            Self::InternalError | Self::Timeout => true,
        }
    }
}

Required methods

If true, the error is non-fatal and the next service in the list will be tried.

Implementations on Foreign Types

Implementors