diff --git a/examples/basic.rs b/examples/basic.rs index e52eac0dc..009a01a1a 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -90,7 +90,7 @@ fn main() { httpcodes::HTTPFound .build() .header("LOCATION", "/index.html") - .body(Body::Empty) + .finish() }))) .bind("127.0.0.1:8080").unwrap() .start(); diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index 80eb30d29..18d926343 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -19,7 +19,7 @@ extern crate env_logger; use actix_web::*; use actix::prelude::*; use diesel::prelude::*; -use futures::future::{Future, ok}; +use futures::future::Future; mod models; mod schema; @@ -35,13 +35,13 @@ fn index(req: HttpRequest) -> Box> Box::new( req.state().db.call_fut(CreateUser{name: name.to_owned()}) + .from_err() .and_then(|res| { match res { - Ok(user) => ok(httpcodes::HTTPOk.build().json(user).unwrap()), - Err(_) => ok(httpcodes::HTTPInternalServerError.response()) + Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?), + Err(_) => Ok(httpcodes::HTTPInternalServerError.response()) } - }) - .map_err(|e| error::ErrorInternalServerError(e).into())) + })) } /// This is db executor actor. We are going to run 3 of them in parallele. diff --git a/examples/multipart/src/main.rs b/examples/multipart/src/main.rs index afe3a3f8d..0778c051c 100644 --- a/examples/multipart/src/main.rs +++ b/examples/multipart/src/main.rs @@ -16,7 +16,7 @@ fn index(mut req: HttpRequest) -> Box> Box::new( req.multipart() // <- get multipart stream for current request - .map_err(Error::from) // <- convert multipart errors + .from_err() // <- convert multipart errors .and_then(|item| { // <- iterate over multipart items match item { // Handle multipart Field diff --git a/examples/template_tera/src/main.rs b/examples/template_tera/src/main.rs index 23d68cadf..86b37e0d6 100644 --- a/examples/template_tera/src/main.rs +++ b/examples/template_tera/src/main.rs @@ -9,19 +9,20 @@ struct State { template: tera::Tera, // <- store tera template in application state } -fn index(req: HttpRequest) -> HttpResponse { +fn index(req: HttpRequest) -> Result { let s = if let Some(name) = req.query().get("name") { // <- submitted form let mut ctx = tera::Context::new(); ctx.add("name", name); ctx.add("text", &"Welcome!".to_owned()); - req.state().template.render("user.html", &ctx).unwrap() + req.state().template.render("user.html", &ctx) + .map_err(|_| error::ErrorInternalServerError("Template error"))? } else { - req.state().template.render("index.html", &tera::Context::new()).unwrap() + req.state().template.render("index.html", &tera::Context::new()) + .map_err(|_| error::ErrorInternalServerError("Template error"))? }; - httpcodes::HTTPOk.build() - .content_type("text/html") - .body(s) - .unwrap() + Ok(httpcodes::HTTPOk.build() + .content_type("text/html") + .body(s)?) } fn main() { diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 8576503a4..8d0d55d98 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -200,12 +200,12 @@ fn main() { let state = WsChatSessionState { addr: server.clone() }; Application::with_state(state) - // redirect to websocket.html - .resource("/", |r| r.method(Method::GET).f(|req| { + // redirect to websocket.html + .resource("/", |r| r.method(Method::GET).f(|_| { httpcodes::HTTPFound .build() .header("LOCATION", "/static/websocket.html") - .body(Body::Empty) + .finish() })) // websocket .resource("/ws/", |r| r.route().f(chat_route))