Rocket/examples/errors/src/main.rs

31 lines
828 B
Rust
Raw Normal View History

2018-10-06 04:56:46 +00:00
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] 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)
}
#[catch(404)]
2019-06-13 02:41:29 +00:00
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])
.register(catchers![not_found])
.launch();
println!("Whoops! Rocket didn't launch!");
println!("This went wrong: {}", e);
}