Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 351757c6ee24bf801cfa3ad6a9fdaaf46258bdc9
parent 112e7008366bfcfa88da385977af3e8a5f8bfd8d
Author: Sergio Benitez <sb@sergio.bz>
Date:   Sun, 16 Sep 2018 01:47:51 -0700

Rename 'Rocket::catch()' to 'Rocket::register()'.

Diffstat:
Mcore/lib/src/catcher.rs | 7+++----
Mcore/lib/src/rocket.rs | 5+++--
Mcore/lib/tests/redirect_from_catcher-issue-113.rs | 4++--
Mexamples/content_types/src/main.rs | 2+-
Mexamples/content_types/src/tests.rs | 2+-
Mexamples/errors/src/main.rs | 2+-
Mexamples/errors/src/tests.rs | 2+-
Mexamples/handlebars_templates/src/main.rs | 2+-
Mexamples/json/src/main.rs | 2+-
Mexamples/manual_routes/src/main.rs | 2+-
Mexamples/tera_templates/src/main.rs | 2+-
Msite/guide/requests.md | 9+++++----
12 files changed, 21 insertions(+), 20 deletions(-)

diff --git 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 @@ -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<Catcher>) -> Self { + pub fn register(mut self, catchers: Vec<Catcher>) -> 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 @@ -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 @@ -51,6 +51,6 @@ fn not_found(request: &Request) -> content::Html<String> { 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 @@ -9,7 +9,7 @@ fn test<H>(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 @@ -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 @@ -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 @@ -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 @@ -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::<ID, String>::new())) } diff --git 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 @@ -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 @@ -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