Add URL to Error in non-2xx case. (#243)

This commit is contained in:
Jacob Hoffman-Andrews
2020-11-22 23:36:45 -08:00
committed by GitHub
parent de4aab7472
commit 3d0cb33596

View File

@@ -86,8 +86,8 @@ impl Request {
/// Sends the request with no body and blocks the caller until done. /// Sends the request with no body and blocks the caller until done.
/// ///
/// Use this with GET, HEAD, or TRACE. It sends neither Content-Length /// Use this with GET, HEAD, OPTIONS or TRACE. It sends neither
/// nor Transfer-Encoding. /// Content-Length nor Transfer-Encoding.
/// ///
/// ``` /// ```
/// # fn main() -> Result<(), ureq::Error> { /// # fn main() -> Result<(), ureq::Error> {
@@ -118,10 +118,11 @@ impl Request {
} }
let reader = payload.into_read(); let reader = payload.into_read();
let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader); let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader);
let response = unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url))?; let response =
unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url.clone()))?;
if response.error() && self.error_on_non_2xx { if response.error() && self.error_on_non_2xx {
Err(ErrorKind::HTTP.new().response(response)) Err(ErrorKind::HTTP.new().url(url.clone()).response(response))
} else { } else {
Ok(response) Ok(response)
} }