Rocket/examples/errors/src/main.rs

32 lines
821 B
Rust
Raw Normal View History

#![feature(plugin, decl_macro)]
2016-09-09 03:38:58 +00:00
#![plugin(rocket_codegen)]
extern crate rocket;
#[cfg(test)] mod tests;
use rocket::response::content;
2017-01-02 06:55:08 +00:00
#[get("/hello/<name>/<age>")]
fn hello(name: String, age: i8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
#[error(404)]
fn not_found(req: &rocket::Request) -> content::Html<String> {
content::Html(format!("<p>Sorry, but '{}' is not a valid path!</p>
<p>Try visiting /hello/&lt;name&gt;/&lt;age&gt; instead.</p>",
req.uri()))
}
fn main() {
let e = rocket::ignite()
// .mount("/", routes![hello, hello]) // uncoment this to get an error
.mount("/", routes![hello])
.catch(errors![not_found])
.launch();
println!("Whoops! Rocket didn't launch!");
println!("This went wrong: {}", e);
}