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

@@ -111,9 +111,9 @@ impl RequestBuilder {
Ok(value) => {
req.headers_mut().append(key, value);
}
Err(e) => error = Some(crate::error::from(e.into())),
Err(e) => error = Some(crate::error::builder(e.into())),
},
Err(e) => error = Some(crate::error::from(e.into())),
Err(e) => error = Some(crate::error::builder(e.into())),
};
}
if let Some(err) = error {
@@ -250,7 +250,7 @@ impl RequestBuilder {
let serializer = serde_urlencoded::Serializer::new(&mut pairs);
if let Err(err) = query.serialize(serializer) {
error = Some(crate::error::from(err));
error = Some(crate::error::builder(err));
}
}
if let Ok(ref mut req) = self.request {
@@ -276,7 +276,7 @@ impl RequestBuilder {
);
*req.body_mut() = Some(body.into());
}
Err(err) => error = Some(crate::error::from(err)),
Err(err) => error = Some(crate::error::builder(err)),
}
}
if let Some(err) = error {
@@ -300,7 +300,7 @@ impl RequestBuilder {
.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
*req.body_mut() = Some(body.into());
}
Err(err) => error = Some(crate::error::from(err)),
Err(err) => error = Some(crate::error::builder(err)),
}
}
if let Some(err) = error {