pub struct Error { /* fields omitted */ }
The Errors that may occur when processing a Request
.
#[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,
}
}
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),
}
}
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");
}
}
Returns a possible URL related to this error.
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);
}
}
}
Returns a reference to the internal error, if available.
The 'static
bounds allows using downcast_ref
to check the
details of the error.
extern crate url;
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);
},
_ => (),
}
}
Returns true if the error is related to HTTP.
Returns true if the error is serialization related.
Returns true if the error is from a RedirectPolicy
.
Returns true if the error is from a request returning a 4xx error.
Returns true if the error is from a request returning a 5xx error.
Returns the status code, if the error was generated from a response.
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Deprecated since 1.33.0:
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
The lower-level source of this error, if any. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Returns a reference to the underlying cause of this failure, if it is an error that wraps other errors. Read more
Returns a reference to the Backtrace
carried by this failure, if it carries one. Read more
fn context<D>(self, context: D) -> Context<D> where D: Display + Send + Sync + 'static, | |
fn compat(self) -> Compat<Self> | |
Wraps this failure in a compatibility wrapper that implements std::error::Error
. Read more
impl<T> AsFail for T where T: Fail, | |
fn as_fail(&self) -> &(dyn Fail + 'static) | |
Converts a reference to Self
into a dynamic trait object of Fail
.