mirror of https://github.com/fafhrd91/actix-web
make Response::message_body fallible
This commit is contained in:
parent
62890c831b
commit
ab3452dee1
|
@ -235,25 +235,27 @@ impl ResponseBuilder {
|
|||
/// This `ResponseBuilder` will be left in a useless state.
|
||||
#[inline]
|
||||
pub fn body<B: Into<Body>>(&mut self, body: B) -> Response<Body> {
|
||||
self.message_body(body.into())
|
||||
match self.message_body(body.into()) {
|
||||
Ok(res) => res,
|
||||
Err(err) => Response::from_error(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate response with a body.
|
||||
///
|
||||
/// This `ResponseBuilder` will be left in a useless state.
|
||||
pub fn message_body<B>(&mut self, body: B) -> Response<B> {
|
||||
// TODO: put error handling back somehow
|
||||
// if let Some(e) = self.err.take() {
|
||||
// return Response::from(Error::from(e)).into_body();
|
||||
// }
|
||||
pub fn message_body<B>(&mut self, body: B) -> Result<Response<B>, Error> {
|
||||
if let Some(err) = self.err.take() {
|
||||
return Err(err.into());
|
||||
}
|
||||
|
||||
let response = self.head.take().expect("cannot reuse response builder");
|
||||
|
||||
Response {
|
||||
Ok(Response {
|
||||
head: response,
|
||||
body: Some(body),
|
||||
error: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Generate response with a streaming body.
|
||||
|
|
|
@ -52,7 +52,7 @@ where
|
|||
|
||||
fn call(&self, (req, mut framed): (Request, Framed<T, h1::Codec>)) -> Self::Future {
|
||||
let fut = async move {
|
||||
let res = ws::handshake(req.head()).unwrap().message_body(());
|
||||
let res = ws::handshake(req.head()).unwrap().message_body(()).unwrap();
|
||||
|
||||
framed
|
||||
.send((res, body::BodySize::None).into())
|
||||
|
|
Loading…
Reference in New Issue