Skip to content

Commit cc1c8e9

Browse files
committed
use create new error approach
1 parent 348b7d9 commit cc1c8e9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/content/content_location.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::headers::{HeaderName, HeaderValue, Headers, CONTENT_LOCATION};
2+
use crate::{Error, StatusCode};
23
use crate::{Status, Url};
34

45
use std::convert::TryInto;
@@ -53,14 +54,14 @@ impl ContentLocation {
5354
// If we successfully parsed the header then there's always at least one
5455
// entry. We want the last entry.
5556
let value = headers.iter().last().unwrap();
56-
let base = base_url.try_into().ok();
57-
match base {
58-
Some(base) => {
59-
let url = base.join(value.as_str().trim()).status(400)?;
60-
Ok(Some(Self { url }))
61-
}
62-
None => Ok(None),
63-
}
57+
let base = base_url.try_into().map_err(|_| {
58+
let mut err = Error::new_adhoc("Invalid base url provided");
59+
err.set_status(StatusCode::BadRequest);
60+
err
61+
})?;
62+
63+
let url = base.join(value.as_str().trim()).status(400)?;
64+
Ok(Some(Self { url }))
6465
}
6566

6667
/// Sets the header.

0 commit comments

Comments
 (0)