diff --git a/core/lib/src/catcher.rs b/core/lib/src/catcher.rs index 95d13582..331ce83c 100644 --- a/core/lib/src/catcher.rs +++ b/core/lib/src/catcher.rs @@ -11,9 +11,8 @@ use yansi::Color::*; /// /// Catchers are routes that run when errors occur. They correspond directly /// with the HTTP error status code they will be handling and are registered -/// with Rocket via the [Rocket::catch](/rocket/struct.Rocket.html#method.catch) -/// method. For example, to handle "404 not found" errors, a catcher for the -/// "404" status code is registered. +/// with Rocket via the [`Rocket::register()`] method. For example, to handle +/// "404 not found" errors, a catcher for the "404" status code is registered. /// /// Because error handlers are only called when all routes are exhausted, they /// should not fail nor forward. If an error catcher fails, the user will @@ -54,7 +53,7 @@ use yansi::Color::*; /// /// fn main() { /// # if false { // We don't actually want to launch the server in an example. -/// rocket::ignite().catch(catchers![internal_error, not_found]).launch(); +/// rocket::ignite().register(catchers![internal_error, not_found]).launch(); /// # } /// } /// ``` diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index a8c6af50..e10a127a 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -562,13 +562,14 @@ impl Rocket { /// /// fn main() { /// # if false { // We don't actually want to launch the server in an example. - /// rocket::ignite().catch(catchers![internal_error, not_found]) + /// rocket::ignite() + /// .register(catchers![internal_error, not_found]) /// # .launch(); /// # } /// } /// ``` #[inline] - pub fn catch(mut self, catchers: Vec) -> Self { + pub fn register(mut self, catchers: Vec) -> Self { info!("{}{}:", Paint::masked("👾 "), Paint::purple("Catchers")); for c in catchers { if self.catchers.get(&c.code).map_or(false, |e| !e.is_default) { diff --git a/core/lib/tests/redirect_from_catcher-issue-113.rs b/core/lib/tests/redirect_from_catcher-issue-113.rs index 878f5b91..c410e9fb 100644 --- a/core/lib/tests/redirect_from_catcher-issue-113.rs +++ b/core/lib/tests/redirect_from_catcher-issue-113.rs @@ -3,7 +3,7 @@ extern crate rocket; -use rocket::{catch, Request, response::Redirect}; +use rocket::{catch, response::Redirect}; #[catch(404)] fn not_found() -> Redirect { @@ -17,7 +17,7 @@ mod tests { #[test] fn error_catcher_redirect() { - let client = Client::new(rocket::ignite().catch(catchers![not_found])).unwrap(); + let client = Client::new(rocket::ignite().register(catchers![not_found])).unwrap(); let response = client.get("/unknown").dispatch(); println!("Response:\n{:?}", response); diff --git a/examples/content_types/src/main.rs b/examples/content_types/src/main.rs index 54f762a2..9afb1b07 100644 --- a/examples/content_types/src/main.rs +++ b/examples/content_types/src/main.rs @@ -51,6 +51,6 @@ fn not_found(request: &Request) -> content::Html { fn main() { rocket::ignite() .mount("/hello", routes![get_hello, post_hello]) - .catch(catchers![not_found]) + .register(catchers![not_found]) .launch(); } diff --git a/examples/content_types/src/tests.rs b/examples/content_types/src/tests.rs index 9d655841..a6865af1 100644 --- a/examples/content_types/src/tests.rs +++ b/examples/content_types/src/tests.rs @@ -9,7 +9,7 @@ fn test(method: Method, uri: &str, header: H, status: Status, body: String) { let rocket = rocket::ignite() .mount("/hello", routes![super::get_hello, super::post_hello]) - .catch(catchers![super::not_found]); + .register(catchers![super::not_found]); let client = Client::new(rocket).unwrap(); let mut response = client.req(method, uri).header(header).dispatch(); diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs index ce376a72..7d0bce2b 100644 --- a/examples/errors/src/main.rs +++ b/examples/errors/src/main.rs @@ -23,7 +23,7 @@ fn main() { let e = rocket::ignite() // .mount("/", routes![hello, hello]) // uncoment this to get an error .mount("/", routes![hello]) - .catch(catchers![not_found]) + .register(catchers![not_found]) .launch(); println!("Whoops! Rocket didn't launch!"); diff --git a/examples/errors/src/tests.rs b/examples/errors/src/tests.rs index 01bc7100..827bc0c6 100644 --- a/examples/errors/src/tests.rs +++ b/examples/errors/src/tests.rs @@ -5,7 +5,7 @@ use rocket::http::Status; fn test(uri: &str, status: Status, body: String) { let rocket = rocket::ignite() .mount("/", routes![super::hello]) - .catch(catchers![super::not_found]); + .register(catchers![super::not_found]); let client = Client::new(rocket).unwrap(); let mut response = client.get(uri).dispatch(); diff --git a/examples/handlebars_templates/src/main.rs b/examples/handlebars_templates/src/main.rs index febe5e65..73028070 100644 --- a/examples/handlebars_templates/src/main.rs +++ b/examples/handlebars_templates/src/main.rs @@ -73,7 +73,7 @@ fn wow_helper( fn rocket() -> rocket::Rocket { rocket::ignite() .mount("/", routes![index, hello, about]) - .catch(catchers![not_found]) + .register(catchers![not_found]) .attach(Template::custom(|engines| { engines.handlebars.register_helper("wow", Box::new(wow_helper)); })) diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index fd84744b..dcc31f1a 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -72,7 +72,7 @@ fn not_found() -> JsonValue { fn rocket() -> rocket::Rocket { rocket::ignite() .mount("/message", routes![new, update, get]) - .catch(catchers![not_found]) + .register(catchers![not_found]) .manage(Mutex::new(HashMap::::new())) } diff --git a/examples/manual_routes/src/main.rs b/examples/manual_routes/src/main.rs index e4c76d1b..dacb9bff 100644 --- a/examples/manual_routes/src/main.rs +++ b/examples/manual_routes/src/main.rs @@ -100,7 +100,7 @@ fn rocket() -> rocket::Rocket { .mount("/hello", vec![name.clone()]) .mount("/hi", vec![name]) .mount("/custom", CustomHandler::new("some data here")) - .catch(vec![not_found_catcher]) + .register(vec![not_found_catcher]) } fn main() { diff --git a/examples/tera_templates/src/main.rs b/examples/tera_templates/src/main.rs index 640170b4..76de8a07 100644 --- a/examples/tera_templates/src/main.rs +++ b/examples/tera_templates/src/main.rs @@ -42,7 +42,7 @@ fn rocket() -> rocket::Rocket { rocket::ignite() .mount("/", routes![index, get]) .attach(Template::fairing()) - .catch(catchers![not_found]) + .register(catchers![not_found]) } fn main() { diff --git a/site/guide/requests.md b/site/guide/requests.md index 9123ff91..2558d9b0 100644 --- a/site/guide/requests.md +++ b/site/guide/requests.md @@ -768,12 +768,13 @@ fn not_found(req: &Request) -> String { ``` Also as with routes, Rocket needs to know about a catcher before it is used to -handle errors. The process is similar to mounting: call the `catch` method with -a list of catchers via the `catchers!` macro. The invocation to add the **404** -catcher declared above looks like: +handle errors. The process, known as "registering" a catcher, is similar to +mounting a route: call the `register` method with a list of catchers via the +`catchers!` macro. The invocation to add the **404** catcher declared above +looks like: ```rust -rocket::ignite().catch(catchers![not_found]) +rocket::ignite().register(catchers![not_found]) ``` Unlike route request handlers, catchers take exactly zero or one parameters. If