#[non_exhaustive]pub enum Error {
Show 14 variants
Api(ApiError),
Http(Box<HttpError>),
Decode(DecodeError),
InvalidRequest(InvalidRequestError),
InvalidConfig(InvalidConfigError),
Closed,
BatchNotSent,
BroadcastFailedChannels(Box<BroadcastFailedChannelsError>),
BatchFailedCommands(Box<BatchFailedCommandsError>),
RetryStopped(Box<RetryStoppedError>),
Timeout(TimeoutError),
Network(NetworkError),
Function(FunctionError),
Payload(PayloadError),
}Expand description
The error of a call. Every call returns one unless it did everything it
was asked: ? is always correct code.
Match it by kind:
match &err {
// Centrifugo refused the request: match the code, never the message.
cent::Error::Api(e) if e.code == cent::ApiError::UNKNOWN_CHANNEL => {}
// Some channels of a broadcast failed; the others got the publication.
cent::Error::BroadcastFailedChannels(e) => {
for (channel, err) in e.errors() {
eprintln!("not published into {channel}: {err}");
}
}
_ if err.is_retryable() => {} // a temporary failure: see `retryable`
_ => {}
}Centrifugo adds error codes over time: an unknown code is still an
Error::Api, so match the codes you handle and treat the rest by kind.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Api(ApiError)
Centrifugo refused the request, or failed to carry it out.
Http(Box<HttpError>)
The request did not reach the API method: an HTTP status other than
200. A 401 means the credentials were refused: see
Error::is_unauthorized.
Decode(DecodeError)
The reply is not Centrifugo’s - usually api_endpoint points
elsewhere.
InvalidRequest(InvalidRequestError)
The client could tell the request is wrong, and did not send it.
InvalidConfig(InvalidConfigError)
The client refuses to work as configured: it was not created, it is
used where it cannot work (another tokio runtime), or a configured
function - Config::with_endpoint_fn or Config::bearer_token -
returned what cannot be sent, an endpoint failing Config::new’s
rules or an empty or malformed token, and nothing was sent. The
message names the option and the fix. Not retryable.
Closed
A call made after the client was closed.
BatchNotSent
A Pending read before its batch was sent.
BroadcastFailedChannels(Box<BroadcastFailedChannelsError>)
Centrifugo carried out a broadcast, and one or more of its channels failed, up to all: the others got the publication.
BatchFailedCommands(Box<BatchFailedCommandsError>)
client only.Centrifugo carried out a batch, and one or more of its commands failed, up to all: each command has its own outcome.
RetryStopped(Box<RetryStoppedError>)
A broadcast with retries stopped by its on_attempt_error callback,
or by its deadline while waiting to retry.
Timeout(TimeoutError)
The call’s deadline passed: its timeout, or the client’s
request_timeout. Every timeout is this error.
Network(NetworkError)
The network failed: a refused or reset connection, a TLS failure.
Function(FunctionError)
The application’s function given to Config::with_endpoint_fn or
Config::bearer_token returned an error: it is the source, and the
message names the function. Judged by retryable
as its source is. What such a function returns and the client cannot
send is an Error::InvalidConfig instead.
Payload(PayloadError)
A payload did not encode, or decode as the type asked: from
json and PayloadExt::decode.
Implementations§
Source§impl Error
impl Error
Sourcepub fn api_code(&self) -> Option<u32>
pub fn api_code(&self) -> Option<u32>
The code of a Centrifugo error, compared with the constants of
ApiError: err.api_code() == Some(ApiError::UNKNOWN_CHANNEL).
None for any other error - a broadcast or batch in which some parts
failed included: look at each part’s error instead.
Whether Centrifugo refused the credentials: an HTTP 401.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Whether the call timed out.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether a new attempt, with time left, may succeed: see retryable.
Sourcepub fn broadcast_result(&self) -> Option<&BroadcastResult>
pub fn broadcast_result(&self) -> Option<&BroadcastResult>
The result of a broadcast in which some channels failed - also inside
Error::RetryStopped: every channel’s outcome.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()