pub enum Error {
Show 20 variants
InvalidBaseUrl(ParseError),
Transport {
kind: TransportKind,
message: String,
source: Option<Arc<dyn Error + Send + Sync>>,
},
Http {
status: StatusCode,
status_text: String,
message: String,
body: Option<Bytes>,
},
Deserialize {
status: StatusCode,
message: String,
body: Option<Bytes>,
},
Timeout,
Cancelled,
BodyTooLarge {
limit: u64,
},
MissingBaseUrl,
RetryExhausted {
attempts: u32,
last: Option<Box<Error>>,
},
Hook(String),
QuerySerialize(String),
InvalidHeaderName(String),
InvalidHeaderValue(String),
MissingPathParam(String),
SchemaRoute {
method: String,
path: String,
},
InvalidAuthHeader(String),
NonReplayableBody,
Io(String),
Config(String),
Other(String),
}Expand description
Error type for better-fetch operations.
Variants§
InvalidBaseUrl(ParseError)
Base URL parsing failed (ClientBuilder::base_url).
Transport
Underlying transport failure (connection, DNS, body read, etc.).
Fields
kind: TransportKindCoarse category aligned with reqwest’s is_* helpers.
Http
Non-success HTTP response (when using throw mode or send_json).
Fields
status: StatusCodeHTTP status code.
Deserialize
JSON response could not be deserialized (feature json).
Timeout
Request exceeded the configured timeout.
Cancelled
Request was cancelled via CancellationToken.
BodyTooLarge
Response body exceeded ClientBuilder::max_response_bytes
or a per-request RequestBuilder::max_response_bytes limit
on buffered (send / send_json) or streaming responses.
MissingBaseUrl
RetryExhausted
Transport retries were exhausted.
Fields
Hook(String)
Returned from on_request or
on_response to abort the pipeline.
Prefer constructing this with Error::hook rather than Error::Other.
QuerySerialize(String)
Query parameter serialization failed (typed endpoint query).
Returned from EndpointRequestBuilder::query and
EndpointQuery::apply_query when serde serialization fails (since 0.4.0).
InvalidHeaderName(String)
Invalid HTTP header name (RequestBuilder::header).
InvalidHeaderValue(String)
Invalid HTTP header value (RequestBuilder::header).
MissingPathParam(String)
A :param segment in the path template was not supplied.
SchemaRoute
Route not registered in a strict SchemaRegistry (feature schema).
InvalidAuthHeader(String)
Invalid Authorization header value.
NonReplayableBody
Request body cannot be replayed for automatic retry (stream or multipart).
Io(String)
I/O error (file writes, etc.).
Config(String)
Internal client configuration error.
Other(String)
Catch-all for rare plugin errors.
Implementations§
Source§impl Error
impl Error
Sourcepub fn transport(kind: TransportKind, message: impl Into<String>) -> Error
pub fn transport(kind: TransportKind, message: impl Into<String>) -> Error
Builds a transport error with an explicit TransportKind.
Sourcepub fn transport_with_source(
kind: TransportKind,
message: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Error
pub fn transport_with_source( kind: TransportKind, message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Error
Builds a transport error with an underlying source error.
Sourcepub fn transport_message(message: impl Into<String>) -> Error
pub fn transport_message(message: impl Into<String>) -> Error
Builds a transport error with TransportKind::Other.
Sourcepub fn transport_source(&self) -> Option<&(dyn Error + Send + Sync)>
pub fn transport_source(&self) -> Option<&(dyn Error + Send + Sync)>
Returns the transport error source when present.
Sourcepub fn transport_kind(&self) -> Option<TransportKind>
pub fn transport_kind(&self) -> Option<TransportKind>
Returns the transport failure category when this error is Error::Transport.
Sourcepub fn transport_detail(&self) -> Option<&str>
pub fn transport_detail(&self) -> Option<&str>
Returns the transport error detail string when this error is Error::Transport.
Sourcepub fn is_transport(&self) -> bool
pub fn is_transport(&self) -> bool
Returns true when this error is Error::Transport.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Returns true when this error is Error::Timeout.
Sourcepub fn http(
status: StatusCode,
message: impl Into<String>,
body: Option<Bytes>,
) -> Error
pub fn http( status: StatusCode, message: impl Into<String>, body: Option<Bytes>, ) -> Error
Builds an HTTP error with canonical status text.
Sourcepub fn http_with_status_text(
status: StatusCode,
status_text: impl Into<String>,
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
Builds an HTTP error with explicit status text.
Sourcepub fn query_serialize(message: impl Into<String>) -> Error
pub fn query_serialize(message: impl Into<String>) -> Error
Builds a query serialization error.
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
Returns the HTTP status when this error is response-related.
Sourcepub fn status_text(&self) -> Option<&str>
pub fn status_text(&self) -> Option<&str>
Returns the canonical status text for Error::Http.
Sourcepub fn body(&self) -> Option<&Bytes>
pub fn body(&self) -> Option<&Bytes>
Returns the response body when present on HTTP, deserialize, or validation errors.
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 retry_exhausted_last(&self) -> Option<&Error>
pub fn retry_exhausted_last(&self) -> Option<&Error>
Returns the last error from Error::RetryExhausted when present.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true when the request was cancelled via CancellationToken.
Sourcepub fn is_body_too_large(&self) -> bool
pub fn is_body_too_large(&self) -> bool
Returns true when the response body exceeded a configured size limit.
Sourcepub fn body_too_large_limit(&self) -> Option<u64>
pub fn body_too_large_limit(&self) -> Option<u64>
Returns the configured byte limit when this error is Error::BodyTooLarge.
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,
Parses the error response body as JSON (for API error payloads).
§Examples
use better_fetch::Error;
use http::StatusCode;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct ApiError {
message: String,
}
let err = Error::http_with_status_text(
StatusCode::BAD_REQUEST,
"Bad Request",
"bad request",
Some(bytes::Bytes::from_static(br#"{"message":"invalid"}"#)),
);
let api: ApiError = err.api_json().unwrap();
assert_eq!(api.message, "invalid");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()