Return a 404 when a file isn't found.

This commit is contained in:
Sergio Benitez 2016-11-02 17:47:00 +01:00
parent 004cae7627
commit d24d5534f4
1 changed files with 4 additions and 3 deletions

View File

@ -6,7 +6,8 @@ extern crate rocket;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use rocket::response::NamedFile; use rocket::response::{NamedFile, Failure};
use rocket::http::StatusCode::NotFound;
#[get("/")] #[get("/")]
fn index() -> io::Result<NamedFile> { fn index() -> io::Result<NamedFile> {
@ -14,8 +15,8 @@ fn index() -> io::Result<NamedFile> {
} }
#[get("/<file..>")] #[get("/<file..>")]
fn files(file: PathBuf) -> io::Result<NamedFile> { fn files(file: PathBuf) -> Result<NamedFile, Failure> {
NamedFile::open(Path::new("static/").join(file)) NamedFile::open(Path::new("static/").join(file)).map_err(|_| Failure(NotFound))
} }
fn main() { fn main() {