Skip to content

Commit

Permalink
Merge pull request #331 from QuietMisdreavus/log-cleaning
Browse files Browse the repository at this point in the history
clean up debug logging around "not found" errors
  • Loading branch information
QuietMisdreavus authored Apr 23, 2019
2 parents 54fff31 + af8c009 commit 7f75260
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ impl Handler for CratesfyiHandler {
self.static_handler.handle(req).or(Err(e))
})
.or_else(|e| {
debug!("{}", e.description());
let err = if let Some(err) = e.error.downcast::<error::Nope>() {
*err
} else if e.error.downcast::<NoRoute>().is_some() {
Expand All @@ -238,33 +237,31 @@ impl Handler for CratesfyiHandler {
panic!("all cratesfyi errors should be of type Nope");
};

match err {
error::Nope::ResourceNotFound => {
// print the path of the URL that triggered a 404 error
struct DebugPath<'a>(&'a iron::Url);
impl<'a> fmt::Display for DebugPath<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for path_elem in self.0.path() {
write!(f, "/{}", path_elem)?;
}

if let Some(query) = self.0.query() {
write!(f, "?{}", query)?;
}

if let Some(hash) = self.0.fragment() {
write!(f, "#{}", hash)?;
}

Ok(())
if let error::Nope::ResourceNotFound = err {
// print the path of the URL that triggered a 404 error
struct DebugPath<'a>(&'a iron::Url);
impl<'a> fmt::Display for DebugPath<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for path_elem in self.0.path() {
write!(f, "/{}", path_elem)?;
}

if let Some(query) = self.0.query() {
write!(f, "?{}", query)?;
}

if let Some(hash) = self.0.fragment() {
write!(f, "#{}", hash)?;
}
}

debug!("Path: {}", DebugPath(&req.url));
Ok(())
}
}
_ => {}

debug!("Path not found: {}", DebugPath(&req.url));
}


Self::chain(err).handle(req)
})
}
Expand Down

0 comments on commit 7f75260

Please sign in to comment.