Skip to content

clean up debug logging around "not found" errors #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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