Skip to main content

Error

Struct Error 

Source
pub struct Error { /* private fields */ }
Available on crate feature client only.
Expand description

Error type for the client.

Implementations§

Source§

impl Error

Source

pub fn is_empty_packet(&self) -> bool

Check if the error is caused by an empty packet.

§Examples
use musli_web::client::RawPacket;

let packet = RawPacket::empty();
let e = packet.decode::<u32>().unwrap_err();

assert!(e.is_empty_packet());
assert!(e.is_decode());
Source

pub fn is_not_connected(&self) -> bool

Check if the request was never sent, since there was no open connection to send it over.

This is the error which is produced if a request is performed while the service is not connected or after it has been dropped. Since the server never saw the request, it is safe to send it again once the connection is open. See Handle::wait_until_open for how to wait until the connection is available.

Source

pub fn is_connection_lost(&self) -> bool

Check if the connection closed before a response to the request arrived.

Unlike is_not_connected, the request was sent, or was being sent, so the server may or may not have handled it. This is the error every pending request gets when the connection closes or when the service is dropped or closed.

Source

pub fn is_cancelled(&self) -> bool

Check if the request was cancelled before it was answered, since another request took its place.

Source

pub fn is_decode(&self) -> bool

Check if the error is caused by something received which could not be decoded.

This covers a response or broadcast whose body does not decode as the requested type, an empty packet, a frame from the server whose header or error message could not be decoded, and a message body in an unknown format. Failing to decode a typed error is one too.

§Examples
use musli_web::client::RawPacket;

let packet = RawPacket::empty();
let e = packet.decode::<u32>().unwrap_err();

assert!(e.is_decode());
Source

pub fn is_invalid_header(&self) -> bool

Check if the error is caused by a header passed to ServiceBuilder::header which cannot be sent, such as a name or a value which is not valid in HTTP.

This is what Service::run and Service::try_connect fail with right away, without trying to connect, since every attempt would send the same header. The underlying error is available through core::error::Error::source.

§Examples
use musli_web::tungstenite030;

let mut service = tungstenite030::connect("ws://127.0.0.1:8080/ws")
    .header("Cookie", "session=\nabc")
    .build();

let error = service.try_connect().await.unwrap_err();
assert!(error.is_invalid_header());
Source

pub fn is_incompatible(&self) -> bool

Check if the server states an application version other than the one this client states, see ServiceBuilder::app_version.

This is what Service::run and Handle::wait_until_open fail with once the service has found out, and the versions on either side are available through State::Incompatible.

Source

pub fn as_server_error(&self) -> Option<&str>

Check if the error is a server error, and if so return the message reported by the server.

Server errors are produced by a Handler which returns an error or which indicates that it does not support the request being made.

This is the message of a typed error too.

Source

pub fn server_error<'de, T>(&'de self) -> Result<Option<T>, Error>
where T: DecodeBody<'de>,

Decode the typed error the server answered with.

A handler which fails with a ws::TypedError<E> sends E encoded in the body format of the connection, see Errors. This decodes it back as T, which should be the same type as E or one which is compatible with it, typically from an API crate shared with the server.

Returns Ok(None) if this is not a server error, or if it is one which carries no typed error, such as a handler error which is plain text or an error the server produced on its own for a request it does not support. Those still have a message, see as_server_error.

§Errors

Errors if the typed error does not decode as T.

§Examples
use musli::{Decode, Encode};
use musli_web::client::Error;

#[derive(Debug, PartialEq, Encode, Decode)]
enum ServerError {
    NotFound,
}

let error = Error::message("Something else");
assert_eq!(error.server_error::<ServerError>().unwrap(), None);
Source

pub fn message(message: impl Display) -> Self

Format a client error consisting of a message.

None of the accessors on Error match an error constructed this way.

Trait Implementations§

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

Auto Trait Implementations§

§

impl !Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasAllProps<(), T> for T

Source§

impl<T> HasAllProps<(), T> for T

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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<E> ResponseError for E
where E: 'static + Send + Display,

Source§

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

Available on crate feature ws only.
Write the human readable message of the error. Read more
Source§

fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>

Available on crate feature ws only.
Encode the typed payload of the error, if it has one, by calling ErrorPayload::encode. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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