mirror of https://github.com/fafhrd91/actix-web
re-add convert errors in builder
This commit is contained in:
parent
40c813a00c
commit
5e77ef66b0
|
@ -310,17 +310,20 @@ impl HttpResponseBuilder {
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn body<B: Into<Body>>(&mut self, body: B) -> HttpResponse {
|
pub fn body<B: Into<Body>>(&mut self, body: B) -> HttpResponse<Body> {
|
||||||
self.message_body(body.into())
|
match self.message_body(body.into()) {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(err) => HttpResponse::from_error(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a body and generate `Response`.
|
/// Set a body and generate `Response`.
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
pub fn message_body<B>(&mut self, body: B) -> HttpResponse<B> {
|
pub fn message_body<B>(&mut self, body: B) -> Result<HttpResponse<B>, Error> {
|
||||||
// if let Some(err) = self.err.take() {
|
if let Some(err) = self.err.take() {
|
||||||
// return HttpResponse::from_error(Error::from(err)).into_body();
|
return Err(err.into());
|
||||||
// }
|
}
|
||||||
|
|
||||||
let res = self
|
let res = self
|
||||||
.res
|
.res
|
||||||
|
@ -336,13 +339,12 @@ impl HttpResponseBuilder {
|
||||||
for cookie in jar.delta() {
|
for cookie in jar.delta() {
|
||||||
match HeaderValue::from_str(&cookie.to_string()) {
|
match HeaderValue::from_str(&cookie.to_string()) {
|
||||||
Ok(val) => res.headers_mut().append(header::SET_COOKIE, val),
|
Ok(val) => res.headers_mut().append(header::SET_COOKIE, val),
|
||||||
Err(err) => res.error = Some(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
// Err(err) => return HttpResponse::from_error(Error::from(err)).into_body(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a streaming body and generate `Response`.
|
/// Set a streaming body and generate `Response`.
|
||||||
|
|
Loading…
Reference in New Issue