pub struct NetworkError {
pub status_code: StatusCode,
pub origin_address: Option<SocketAddr>,
pub raw_body: Option<Bytes>,
}
Expand description
Represents any non-200 HTTP status code
§Example
use httpmock::prelude::*;
use rust_fetch::Fetch;
#[tokio::main]
async fn main() {
let server = MockServer::start();
let fetch = Fetch::new(&server.base_url(), None).unwrap();
server.mock(|when, then| {
when.path("/test").method(GET);
then.status(400);
});
let response = fetch.get::<()>("/test", None).await;
if let Err(rust_fetch::FetchError::NetworkError(ref err)) = response {
assert_eq!(400, err.status_code);
assert_eq!(Some(*server.address()), err.origin_address);
assert_eq!(false, err.raw_body.is_none());
} else {
panic!("Result was not an instance of NetworkError");
}
assert!(response.is_err());
}
Fields§
§status_code: StatusCode
§origin_address: Option<SocketAddr>
§raw_body: Option<Bytes>
Implementations§
Trait Implementations§
Source§impl Debug for NetworkError
impl Debug for NetworkError
Source§impl Display for NetworkError
impl Display for NetworkError
Source§impl Error for NetworkError
impl Error for NetworkError
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 NetworkError
impl RefUnwindSafe for NetworkError
impl Send for NetworkError
impl Sync for NetworkError
impl Unpin for NetworkError
impl UnwindSafe for NetworkError
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