Rewrite the Error type. (#234)

This adds a source field to keep track of upstream errors and allow
backtraces, plus a URL field to indicate what URL an error was
associated with.

The enum variants we used to use for Error are now part of a new
ErrorKind type. For convenience within ureq, ErrorKinds can be turned
into an Error with `.new()` or `.msg("some additional information")`.

Error acts as a builder, so additional information can be added after
initial construction. For instance, we return a DnsFailed error when
name resolution fails. When that error bubbles up to Request's
`do_call`, Request adds the URL.

Fixes #232.
This commit is contained in:
Jacob Hoffman-Andrews
2020-11-21 16:14:44 -08:00
committed by GitHub
parent dac517e30e
commit fade03b54e
13 changed files with 266 additions and 122 deletions

View File

@@ -215,7 +215,7 @@ mod testserver;
pub use crate::agent::Agent;
pub use crate::agent::AgentBuilder;
pub use crate::error::Error;
pub use crate::error::{Error, ErrorKind};
pub use crate::header::Header;
pub use crate::proxy::Proxy;
pub use crate::request::Request;
@@ -336,6 +336,7 @@ mod tests {
#[cfg(feature = "tls")]
fn connect_https_invalid_name() {
let result = get("https://example.com{REQUEST_URI}/").call();
assert!(matches!(result.unwrap_err(), Error::DnsFailed(_)));
let e = ErrorKind::DnsFailed;
assert_eq!(result.unwrap_err().kind(), e);
}
}