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