Skip to content
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

Fixes #55 #1095

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions src/web/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod tests {
.next()
.unwrap()
.text_contents(),
"The requested resource does not exist",
"The requested crate does not exist",
);

Ok(())
Expand All @@ -154,7 +154,7 @@ mod tests {
#[test]
fn check_404_page_content_resource() {
// Resources with a `.js` and `.ico` extension are special cased in the
// routes_handler which is currently run last. This means that `get("resource.exe")` will
// routes_handler. This means that `get("resource.exe")` will
// fail with a `no so such crate` instead of 'no such resource'
wrapper(|env| {
let page = kuchiki::parse_html().one(
Expand Down Expand Up @@ -190,7 +190,7 @@ mod tests {
.next()
.unwrap()
.text_contents(),
"The requested resource does not exist",
"The requested version does not exist",
);

Ok(())
Expand All @@ -209,7 +209,7 @@ mod tests {
.next()
.unwrap()
.text_contents(),
"The requested resource does not exist",
"The requested version does not exist",
);

Ok(())
Expand All @@ -232,7 +232,7 @@ mod tests {
.next()
.unwrap()
.text_contents(),
"The requested resource does not exist",
"The requested version does not exist",
);

Ok(())
Expand Down
14 changes: 7 additions & 7 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ impl Handler for CratesfyiHandler {
e: IronError,
handle: impl FnOnce() -> IronResult<Response>,
) -> IronResult<Response> {
if e.response.status == Some(status::NotFound) {
handle()
let is_404 = |err: &IronError| err.response.status == Some(status::NotFound);
if is_404(&e) {
// we want to keep the original error from the router_handler
// in case of a 404, because it provides the best error messages to the user
handle().map_err(|err| if is_404(&err) { e } else { err })
} else {
Err(e)
}
};

// try serving shared rustdoc resources first, then db/static file handler and last router
// return 404 if none of them return Ok. It is important that the router comes last,
// because it gives the most specific errors, e.g. CrateNotFound or VersionNotFound
self.shared_resource_handler
self.router_handler
.handle(req)
.or_else(|e| if_404(e, || self.router_handler.handle(req)))
.or_else(|e| if_404(e, || self.shared_resource_handler.handle(req)))
.or_else(|e| if_404(e, || self.database_file_handler.handle(req)))
.or_else(|e| if_404(e, || self.static_handler.handle(req)))
.or_else(|e| {
Expand Down