Redesign Error type

- The `Error`'s kind is a now a set of variants depending on the context
  of when an error could occur.
- If another error was the cause, it is now always the `source`.

Along with the `is_*` methods, this should help in understanding *when*
a certain error occurred. For example, an error setting the TLS
certificates will return a builder error, with the TLS error as the
source. This should help differentiate from a TLS error that happens
when connecting to a server.

It also makes the internal code less dependent on all the exact
dependencies that can be enabled or disabled.
This commit is contained in:
Sean McArthur
2019-09-17 12:55:20 -07:00
parent 6b5be07158
commit 53495e1526
20 changed files with 209 additions and 544 deletions

View File

@@ -205,8 +205,8 @@ impl Response {
/// [`serde_json::from_reader`]: https://docs.serde.rs/serde_json/fn.from_reader.html
pub fn json<T: DeserializeOwned>(self) -> crate::Result<T> {
wait::timeout(self.inner.json(), self.timeout).map_err(|e| match e {
wait::Waited::TimedOut => crate::error::timedout(None),
wait::Waited::Executor(e) => crate::error::from(e),
wait::Waited::TimedOut(e) => crate::error::decode(e),
wait::Waited::Executor(e) => crate::error::decode(e),
wait::Waited::Inner(e) => e,
})
}
@@ -253,8 +253,8 @@ impl Response {
pub fn text_with_charset(self, default_encoding: &str) -> crate::Result<String> {
wait::timeout(self.inner.text_with_charset(default_encoding), self.timeout).map_err(|e| {
match e {
wait::Waited::TimedOut => crate::error::timedout(None),
wait::Waited::Executor(e) => crate::error::from(e),
wait::Waited::TimedOut(e) => crate::error::decode(e),
wait::Waited::Executor(e) => crate::error::decode(e),
wait::Waited::Inner(e) => e,
}
})
@@ -284,7 +284,7 @@ impl Response {
where
W: io::Write,
{
io::copy(self, w).map_err(crate::error::from)
io::copy(self, w).map_err(crate::error::response)
}
/// Turn a response into an error if the server returned an error.
@@ -359,8 +359,8 @@ impl Read for Response {
let timeout = self.timeout;
wait::timeout(self.body_mut().read(buf), timeout).map_err(|e| match e {
wait::Waited::TimedOut => crate::error::timedout(None).into_io(),
wait::Waited::Executor(e) => crate::error::from(e).into_io(),
wait::Waited::TimedOut(e) => crate::error::response(e).into_io(),
wait::Waited::Executor(e) => crate::error::response(e).into_io(),
wait::Waited::Inner(e) => e,
})
}