pub enum Error {
InvalidBaseUrl(ParseError),
Transport(String),
Http {
status: StatusCode,
status_text: String,
message: String,
body: Option<Bytes>,
},
Deserialize {
status: StatusCode,
message: String,
body: Option<Bytes>,
},
Timeout,
Cancelled,
MissingBaseUrl,
RetryExhausted {
attempts: u32,
last: Option<String>,
},
Hook(String),
Other(String),
}Expand description
Error type for better-fetch operations.
Variants§
InvalidBaseUrl(ParseError)
Transport(String)
Http
Deserialize
Timeout
Cancelled
MissingBaseUrl
RetryExhausted
Hook(String)
Returned from on_request or
on_response to abort the pipeline.
Prefer constructing this with Error::hook rather than Error::Other.
Other(String)
Implementations§
Source§impl Error
impl Error
pub fn http( status: StatusCode, message: impl Into<String>, body: Option<Bytes>, ) -> Error
pub fn http_with_status_text( status: StatusCode, status_text: impl Into<String>, message: impl Into<String>, body: Option<Bytes>, ) -> Error
pub fn status(&self) -> Option<StatusCode>
pub fn status_text(&self) -> Option<&str>
pub fn body(&self) -> Option<&Bytes>
Sourcepub fn is_retry_exhausted(&self) -> bool
pub fn is_retry_exhausted(&self) -> bool
Returns true when transport retries were configured but all attempts failed.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true when the request was cancelled via CancellationToken.
Sourcepub fn hook(msg: impl Into<String>) -> Error
pub fn hook(msg: impl Into<String>) -> Error
Builds a hook failure for Hooks::on_request /
Hooks::on_response.
Sourcepub fn is_hook(&self) -> bool
pub fn is_hook(&self) -> bool
Returns true when the error is Error::Hook.
Sourcepub fn api_json<T>(&self) -> Option<T>where
T: DeserializeOwned,
pub fn api_json<T>(&self) -> Option<T>where
T: DeserializeOwned,
Parse the error response body as JSON (for API error payloads).
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)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(source: ParseError) -> Error
fn from(source: ParseError) -> Error
Converts to this type from the input type.
Auto Trait Implementations§
impl !Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
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
Mutably borrows from an owned value. Read more