Skip to content

Commit

Permalink
Redirect to an error page when file's not found
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Nov 26, 2015
1 parent 3eef814 commit b17ca9b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
9 changes: 6 additions & 3 deletions components/net/about_loader.rs
Expand Up @@ -19,7 +19,9 @@ pub fn factory(mut load_data: LoadData,
start_chan: LoadConsumer,
classifier: Arc<MIMEClassifier>,
cancel_listener: CancellationListener) {
match load_data.url.non_relative_scheme_data().unwrap() {
let url = load_data.url.clone();
let non_relative_scheme_data = url.non_relative_scheme_data().unwrap();
match non_relative_scheme_data {
"blank" => {
let metadata = Metadata {
final_url: load_data.url,
Expand All @@ -34,9 +36,10 @@ pub fn factory(mut load_data: LoadData,
return
}
"crash" => panic!("Loading the about:crash URL."),
"failure" => {
"failure" | "not-found" => {
let mut path = resources_dir_path();
path.push("failure.html");
let file_name = non_relative_scheme_data.to_owned() + ".html";
path.push(&file_name);
assert!(path.exists());
load_data.url = Url::from_file_path(&*path).unwrap();
}
Expand Down
11 changes: 9 additions & 2 deletions components/net/file_loader.rs
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use about_loader;
use mime_classifier::MIMEClassifier;
use net_traits::ProgressMsg::{Done, Payload};
use net_traits::{LoadConsumer, LoadData, Metadata};
Expand All @@ -13,6 +14,7 @@ use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::sync::Arc;
use url::Url;
use util::task::spawn_named;

static READ_SIZE: usize = 8192;
Expand Down Expand Up @@ -96,8 +98,13 @@ pub fn factory(load_data: LoadData,
}
};
}
Err(e) => {
send_error(url, e.description().to_owned(), senders);
Err(_) => {
// this should be one of the three errors listed in
// http://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open
// but, we'll go for a "file not found!"
let url = Url::parse("about:not-found").unwrap();
let load_data_404 = LoadData::new(url, None);
about_loader::factory(load_data_404, senders, classifier, cancel_listener)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions resources/not-found.html
@@ -0,0 +1,9 @@
<html>
<head>
<title>about:not-found</title>
</head>
<body>
<!-- courtesy of https://mozillians.org/blahblah -->
<img src="tumbeast.png">
</body>
</html>
Binary file added resources/tumbeast.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b17ca9b

Please sign in to comment.