[−][src]Struct reqwest::Error
The Errors that may occur when processing a Request
.
Examples
#[macro_use] extern crate serde_derive; extern crate reqwest; #[derive(Deserialize)] struct Simple { key: String } fn run() { match make_request() { Err(e) => handler(e), Ok(_) => return, } } // Response is not a json object conforming to the Simple struct fn make_request() -> Result<Simple, reqwest::Error> { reqwest::get("http://httpbin.org/ip")?.json() } fn handler(e: reqwest::Error) { if e.is_http() { match e.url() { None => println!("No Url given"), Some(url) => println!("Problem making request to: {}", url), } } // Inspect the internal error and output it if e.is_serialization() { let serde_error = match e.get_ref() { None => return, Some(err) => err, }; println!("problem parsing information {}", serde_error); } if e.is_redirect() { println!("server redirecting too many times or making loop"); } }
Methods
impl Error
[src]
impl Error
pub fn url(&self) -> Option<&Url>
[src]
pub fn url(&self) -> Option<&Url>
Returns a possible URL related to this error.
Examples
// displays last stop of a redirect loop let response = reqwest::get("http://site.with.redirect.loop"); if let Err(e) = response { if e.is_redirect() { if let Some(final_stop) = e.url() { println!("redirect loop at {}", final_stop); } } }
pub fn get_ref(&self) -> Option<&(dyn StdError + Send + Sync + 'static)>
[src]
pub fn get_ref(&self) -> Option<&(dyn StdError + Send + Sync + 'static)>
Returns a reference to the internal error, if available.
The 'static
bounds allows using downcast_ref
to check the
details of the error.
Examples
extern crate url; // retries requests with no host on localhost let invalid_request = "http://"; let mut response = reqwest::get(invalid_request); if let Err(e) = response { match e.get_ref().and_then(|e| e.downcast_ref::<url::ParseError>()) { Some(&url::ParseError::EmptyHost) => { let valid_request = format!("{}{}",invalid_request, "localhost"); response = reqwest::get(&valid_request); }, _ => (), } }
pub fn is_http(&self) -> bool
[src]
pub fn is_http(&self) -> bool
Returns true if the error is related to HTTP.
pub fn is_serialization(&self) -> bool
[src]
pub fn is_serialization(&self) -> bool
Returns true if the error is serialization related.
pub fn is_redirect(&self) -> bool
[src]
pub fn is_redirect(&self) -> bool
Returns true if the error is from a RedirectPolicy
.
pub fn is_client_error(&self) -> bool
[src]
pub fn is_client_error(&self) -> bool
Returns true if the error is from a request returning a 4xx error.
pub fn is_server_error(&self) -> bool
[src]
pub fn is_server_error(&self) -> bool
Returns true if the error is from a request returning a 5xx error.
pub fn status(&self) -> Option<StatusCode>
[src]
pub fn status(&self) -> Option<StatusCode>
Returns the status code, if the error was generated from a response.
Trait Implementations
impl Display for Error
[src]
impl Display for Error
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Debug for Error
[src]
impl Debug for Error
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Error for Error
[src]
impl Error for Error
fn description(&self) -> &str
[src]
fn description(&self) -> &str
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn StdError>
[src]
fn cause(&self) -> Option<&dyn StdError>
: replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
[src]
impl<T> Erased for T