pub struct ApiError {
pub status: StatusCode,
pub body: Value,
pub headers: HeaderMap,
pub endpoint: Option<String>,
}Expand description
An unsuccessful HTTP response with its body and request metadata.
Display and Debug omit the body and arbitrary headers. Inspect Self::message
or body explicitly when server details are appropriate to expose.
Fields§
§status: StatusCodeHTTP response status.
body: ValueJSON error data, response text as a string, or null for an empty body.
headers: HeaderMapThe original response headers.
endpoint: Option<String>Request method and URL, without URL credentials, query, or fragment.
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn new(
status: StatusCode,
body: Value,
headers: HeaderMap,
endpoint: Option<String>,
) -> Self
pub fn new( status: StatusCode, body: Value, headers: HeaderMap, endpoint: Option<String>, ) -> Self
Construct an API error and sanitize the optional endpoint.
Sourcepub fn kind(&self) -> ApiErrorKind
pub fn kind(&self) -> ApiErrorKind
Classify the error by its HTTP status.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
The x-typesafe-request-id response header, if valid UTF-8.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Server-requested retry delay, preferring retry-after-ms.
Trait Implementations§
Source§impl Error for ApiError
impl Error for ApiError
1.30.0 · 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()
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl UnwindSafe for ApiError
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