diff --git a/src/lib.rs b/src/lib.rs index 945a1c4..9fd4349 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,33 @@ pub struct Wiki { paths: Vec, } +fn get_http_error_as_html(status: iron::status::Status) -> (iron::mime::Mime, iron::status::Status, &'static str) { + + match status { + status::NotFound => + (ContentType::html().0, status, " + + 404 Not Found + +

Not found

+

The requested page was not found on this server.

+ + +"), + + status::InternalServerError => (ContentType::html().0, status, " + + 500 Internal server error + +

Internal server error

+ + +"), + + _ => (ContentType::html().0, status, "") + } +} + impl Wiki { /// Create a new `Wiki` instance pub fn new() -> Self { @@ -168,18 +195,18 @@ impl Wiki { } if !path.exists() { - return Ok(Response::with(status::InternalServerError)); + return Ok(Response::with(get_http_error_as_html(status::NotFound))); } let mut f = match File::open(path) { Ok(v) => v, - _ => return Ok(Response::with(status::NotFound)), + _ => return Ok(Response::with(get_http_error_as_html(status::NotFound))), }; let mut buffer = String::new(); match f.read_to_string(&mut buffer) { Ok(v) => v, - _ => return Ok(Response::with(status::InternalServerError)), + _ => return Ok(Response::with(get_http_error_as_html(status::InternalServerError))), }; /* Content type needs to be determined from the file rather than assuming html */