Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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>)

Available on crate feature 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

Source

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.

Source

pub fn is_unauthorized(&self) -> bool

Whether Centrifugo refused the credentials: an HTTP 401.

Source

pub fn is_timeout(&self) -> bool

Whether the call timed out.

Source

pub fn is_retryable(&self) -> bool

Whether a new attempt, with time left, may succeed: see retryable.

Source

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 Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Serialize for Error

An error inside a result - a channel’s in a broadcast, a command’s in a batch - encodes as {"code": ..., "message": ...} for a Centrifugo error, and {"message": ...} for any other (spec 3.7).

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more