diff --git a/actix-http/src/response_builder.rs b/actix-http/src/response_builder.rs index 32217662a..63ba37fd9 100644 --- a/actix-http/src/response_builder.rs +++ b/actix-http/src/response_builder.rs @@ -235,25 +235,27 @@ impl ResponseBuilder { /// This `ResponseBuilder` will be left in a useless state. #[inline] pub fn body>(&mut self, body: B) -> Response { - 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(&mut self, body: B) -> Response { - // 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(&mut self, body: B) -> Result, 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. diff --git a/actix-http/tests/test_ws.rs b/actix-http/tests/test_ws.rs index 72870bab5..bf1ca9385 100644 --- a/actix-http/tests/test_ws.rs +++ b/actix-http/tests/test_ws.rs @@ -52,7 +52,7 @@ where fn call(&self, (req, mut framed): (Request, Framed)) -> 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())