pub struct Error { /* private fields */ }client only.Expand description
Error type for the client.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_empty_packet(&self) -> bool
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());Sourcepub fn is_not_connected(&self) -> bool
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.
Sourcepub fn is_connection_lost(&self) -> bool
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.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the request was cancelled before it was answered, since another request took its place.
Sourcepub fn is_decode(&self) -> bool
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());Sourcepub fn is_invalid_header(&self) -> bool
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());Sourcepub fn is_incompatible(&self) -> bool
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.
Sourcepub fn as_server_error(&self) -> Option<&str>
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.
Sourcepub fn server_error<'de, T>(&'de self) -> Result<Option<T>, Error>where
T: DecodeBody<'de>,
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);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()
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§
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> HasAllProps<(), T> for T
impl<T> HasAllProps<(), T> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> ResponseError for E
impl<E> ResponseError for E
Source§fn fmt_message(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt_message(&self, f: &mut Formatter<'_>) -> Result<(), Error>
ws only.Source§fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
ws only.ErrorPayload::encode. Read more