1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-26 11:31:09 +00:00

Use more ergonomic actix_web::Error instead of http::Error for ClientRequestBuilder::body()

This commit is contained in:
Nikolay Kim 2018-03-21 20:19:31 -07:00
parent e49910cdab
commit 93d99b5a49
3 changed files with 12 additions and 10 deletions

View file

@ -6,6 +6,8 @@
* Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()` * Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()`
* Use more ergonomic `actix_web::Error` instead of `http::Error` for `ClientRequestBuilder::body()`
## 0.4.10 (2018-03-20) ## 0.4.10 (2018-03-20)

View file

@ -542,9 +542,9 @@ impl ClientRequestBuilder {
/// Set a body and generate `ClientRequest`. /// Set a body and generate `ClientRequest`.
/// ///
/// `ClientRequestBuilder` can not be used after this call. /// `ClientRequestBuilder` can not be used after this call.
pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<ClientRequest, HttpError> { pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<ClientRequest, Error> {
if let Some(e) = self.err.take() { if let Some(e) = self.err.take() {
return Err(e) return Err(e.into())
} }
if self.default_headers { if self.default_headers {
@ -596,13 +596,13 @@ impl ClientRequestBuilder {
self.header(header::CONTENT_TYPE, "application/json"); self.header(header::CONTENT_TYPE, "application/json");
} }
Ok(self.body(body)?) self.body(body)
} }
/// Set a streaming body and generate `ClientRequest`. /// Set a streaming body and generate `ClientRequest`.
/// ///
/// `ClientRequestBuilder` can not be used after this call. /// `ClientRequestBuilder` can not be used after this call.
pub fn streaming<S, E>(&mut self, stream: S) -> Result<ClientRequest, HttpError> pub fn streaming<S, E>(&mut self, stream: S) -> Result<ClientRequest, Error>
where S: Stream<Item=Bytes, Error=E> + 'static, where S: Stream<Item=Bytes, Error=E> + 'static,
E: Into<Error>, E: Into<Error>,
{ {
@ -612,7 +612,7 @@ impl ClientRequestBuilder {
/// Set an empty body and generate `ClientRequest` /// Set an empty body and generate `ClientRequest`
/// ///
/// `ClientRequestBuilder` can not be used after this call. /// `ClientRequestBuilder` can not be used after this call.
pub fn finish(&mut self) -> Result<ClientRequest, HttpError> { pub fn finish(&mut self) -> Result<ClientRequest, Error> {
self.body(Body::Empty) self.body(Body::Empty)
} }

View file

@ -18,7 +18,7 @@ use futures::unsync::mpsc::{unbounded, UnboundedSender};
use actix::prelude::*; use actix::prelude::*;
use body::{Body, Binary}; use body::{Body, Binary};
use error::UrlParseError; use error::{Error, UrlParseError};
use header::IntoHeaderValue; use header::IntoHeaderValue;
use payload::PayloadHelper; use payload::PayloadHelper;
use httpmessage::HttpMessage; use httpmessage::HttpMessage;
@ -68,7 +68,7 @@ pub enum ClientError {
#[fail(display="Invalid challenge response")] #[fail(display="Invalid challenge response")]
InvalidChallengeResponse(String, HeaderValue), InvalidChallengeResponse(String, HeaderValue),
#[fail(display="Http parsing error")] #[fail(display="Http parsing error")]
Http(HttpError), Http(Error),
#[fail(display="Url parsing error")] #[fail(display="Url parsing error")]
Url(UrlParseError), Url(UrlParseError),
#[fail(display="Response parsing error")] #[fail(display="Response parsing error")]
@ -83,8 +83,8 @@ pub enum ClientError {
Disconnected, Disconnected,
} }
impl From<HttpError> for ClientError { impl From<Error> for ClientError {
fn from(err: HttpError) -> ClientError { fn from(err: Error) -> ClientError {
ClientError::Http(err) ClientError::Http(err)
} }
} }
@ -224,7 +224,7 @@ impl Client {
ClientHandshake::error(e) ClientHandshake::error(e)
} }
else if let Some(e) = self.http_err.take() { else if let Some(e) = self.http_err.take() {
ClientHandshake::error(e.into()) ClientHandshake::error(Error::from(e).into())
} else { } else {
// origin // origin
if let Some(origin) = self.origin.take() { if let Some(origin) = self.origin.take() {