pub struct ApiError<E> {
pub status: u16,
pub headers: HeaderMap,
pub body: String,
pub raw_body: Vec<u8>,
pub typed: Option<E>,
pub parse_error: Option<String>,
}Expand description
Envelope returned for any HTTP response that we received but couldn’t (or didn’t) treat as a successful typed result.
Includes both non-2xx responses and 2xx responses whose body
failed to deserialize into the expected success type. status,
headers, and raw_body preserve what the server actually sent,
while body is a convenient lossy UTF-8 rendering. typed
carries the parsed per-operation error variant
when the body matched a declared schema. Formatting the error
limits only the displayed body preview; the public fields
retain the complete response and parsing details.
Fields§
§status: u16§headers: HeaderMap§body: String§raw_body: Vec<u8>Exact response bytes before lossy UTF-8 conversion.
typed: Option<E>§parse_error: Option<String>Implementations§
Source§impl<E> ApiError<E>
impl<E> ApiError<E>
pub fn is_client_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Retry guidance for the response. Mirrors the previous HttpError logic for backwards-compatible retry middleware.
Sourcepub fn problem_details(&self) -> Option<ProblemDetails>
pub fn problem_details(&self) -> Option<ProblemDetails>
Decode the generated RFC 9457 validation-problem profile
without replacing a documented per-operation error in typed.
Returns None unless the response’s Content-Type is
application/problem+json, which is how RFC 9457 identifies
a problem document. Most third-party APIs return their
errors as plain application/json, so this yields None
against them by design — use typed for a documented
per-operation error body, or body for the raw payload.
Servers generated by this tool always emit the problem
media type, so this succeeds against them.
Trait Implementations§
Source§impl<E: Debug> Error for ApiError<E>
impl<E: Debug> Error for ApiError<E>
1.30.0 · 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()