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:
committed by
GitHub
parent
dac517e30e
commit
fade03b54e
@@ -4,7 +4,7 @@ use std::{
|
||||
};
|
||||
use testserver::{self, TestServer};
|
||||
|
||||
use crate::test;
|
||||
use crate::{error::Error, test};
|
||||
|
||||
use super::super::*;
|
||||
|
||||
@@ -34,7 +34,7 @@ fn redirect_many() {
|
||||
.build()
|
||||
.get("test://host/redirect_many1")
|
||||
.call();
|
||||
assert!(matches!(result, Err(Error::TooManyRedirects)));
|
||||
assert!(matches!(result, Err(e) if e.kind() == ErrorKind::TooManyRedirects));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -104,12 +104,11 @@ fn redirect_host() {
|
||||
Ok(())
|
||||
});
|
||||
let url = format!("http://localhost:{}/", srv.port);
|
||||
let resp = crate::Agent::new().get(&url).call();
|
||||
let err = resp.err();
|
||||
let result = crate::Agent::new().get(&url).call();
|
||||
assert!(
|
||||
matches!(err, Some(Error::DnsFailed(_))),
|
||||
"expected DnsFailed, got: {:?}",
|
||||
err
|
||||
matches!(result, Err(ref e) if e.kind() == ErrorKind::DnsFailed),
|
||||
"expected Err(DnsFailed), got: {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user