Merge pull request #138 from budziq/error_docs_update
Error docs update
This commit is contained in:
@@ -116,6 +116,10 @@ struct Config {
|
|||||||
|
|
||||||
impl ClientBuilder {
|
impl ClientBuilder {
|
||||||
/// Constructs a new `ClientBuilder`
|
/// Constructs a new `ClientBuilder`
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created.
|
||||||
pub fn new() -> ::Result<ClientBuilder> {
|
pub fn new() -> ::Result<ClientBuilder> {
|
||||||
let tls_connector_builder = try_!(native_tls::TlsConnector::builder());
|
let tls_connector_builder = try_!(native_tls::TlsConnector::builder());
|
||||||
Ok(ClientBuilder {
|
Ok(ClientBuilder {
|
||||||
@@ -132,10 +136,14 @@ impl ClientBuilder {
|
|||||||
|
|
||||||
/// Returns a `Client` that uses this `ClientBuilder` configuration.
|
/// Returns a `Client` that uses this `ClientBuilder` configuration.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This consumes the internal state of the builder. Trying to use this
|
/// This method fails if native TLS backend cannot be initialized.
|
||||||
/// builder again after calling `build` will panic.
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This method consumes the internal state of the builder.
|
||||||
|
/// Trying to use this builder again after calling `build` will panic.
|
||||||
pub fn build(&mut self) -> ::Result<Client> {
|
pub fn build(&mut self) -> ::Result<Client> {
|
||||||
let config = self.take_config();
|
let config = self.take_config();
|
||||||
|
|
||||||
@@ -170,6 +178,10 @@ impl ClientBuilder {
|
|||||||
///
|
///
|
||||||
/// This can be used to connect to a server that has a self-signed
|
/// This can be used to connect to a server that has a self-signed
|
||||||
/// certificate for example.
|
/// certificate for example.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if adding root certificate was unsuccessful.
|
||||||
pub fn add_root_certificate(&mut self, cert: Certificate) -> ::Result<&mut ClientBuilder> {
|
pub fn add_root_certificate(&mut self, cert: Certificate) -> ::Result<&mut ClientBuilder> {
|
||||||
try_!(self.config_mut().tls.add_root_certificate(cert.0));
|
try_!(self.config_mut().tls.add_root_certificate(cert.0));
|
||||||
Ok(self)
|
Ok(self)
|
||||||
@@ -246,43 +258,75 @@ impl ClientBuilder {
|
|||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Constructs a new `Client`.
|
/// Constructs a new `Client`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created or initialized.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> ::Result<Client> {
|
pub fn new() -> ::Result<Client> {
|
||||||
ClientBuilder::new()?.build()
|
ClientBuilder::new()?.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `ClientBuilder` to configure a `Client`.
|
/// Creates a `ClientBuilder` to configure a `Client`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn builder() -> ::Result<ClientBuilder> {
|
pub fn builder() -> ::Result<ClientBuilder> {
|
||||||
ClientBuilder::new()
|
ClientBuilder::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `GET` request to a URL.
|
/// Convenience method to make a `GET` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn get<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn get<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Get, url)
|
self.request(Method::Get, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `POST` request to a URL.
|
/// Convenience method to make a `POST` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn post<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn post<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Post, url)
|
self.request(Method::Post, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `PUT` request to a URL.
|
/// Convenience method to make a `PUT` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn put<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn put<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Put, url)
|
self.request(Method::Put, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `PATCH` request to a URL.
|
/// Convenience method to make a `PATCH` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn patch<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn patch<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Patch, url)
|
self.request(Method::Patch, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `DELETE` request to a URL.
|
/// Convenience method to make a `DELETE` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn delete<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn delete<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Delete, url)
|
self.request(Method::Delete, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `HEAD` request to a URL.
|
/// Convenience method to make a `HEAD` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn head<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn head<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Head, url)
|
self.request(Method::Head, url)
|
||||||
}
|
}
|
||||||
@@ -291,6 +335,10 @@ impl Client {
|
|||||||
///
|
///
|
||||||
/// Returns a `RequestBuilder`, which will allow setting headers and
|
/// Returns a `RequestBuilder`, which will allow setting headers and
|
||||||
/// request body before sending.
|
/// request body before sending.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> ::Result<RequestBuilder> {
|
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> ::Result<RequestBuilder> {
|
||||||
let url = try_!(url.into_url());
|
let url = try_!(url.into_url());
|
||||||
Ok(request::builder(self.clone(), Request::new(method, url)))
|
Ok(request::builder(self.clone(), Request::new(method, url)))
|
||||||
@@ -303,6 +351,11 @@ impl Client {
|
|||||||
///
|
///
|
||||||
/// You should prefer to use the `RequestBuilder` and
|
/// You should prefer to use the `RequestBuilder` and
|
||||||
/// `RequestBuilder::send()`.
|
/// `RequestBuilder::send()`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if there was an error while sending request,
|
||||||
|
/// redirect loop was detected or redirect limit was exhausted.
|
||||||
pub fn execute(&self, request: Request) -> ::Result<Response> {
|
pub fn execute(&self, request: Request) -> ::Result<Response> {
|
||||||
self.inner.execute_request(request)
|
self.inner.execute_request(request)
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/lib.rs
10
src/lib.rs
@@ -208,6 +208,16 @@ mod response;
|
|||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function fails if:
|
||||||
|
///
|
||||||
|
/// - native TLS backend cannot be initialized
|
||||||
|
/// - supplied `Url` cannot be parsed
|
||||||
|
/// - there was an error while sending request
|
||||||
|
/// - redirect loop was detected
|
||||||
|
/// - redirect limit was exhausted
|
||||||
pub fn get<T: IntoUrl>(url: T) -> ::Result<Response> {
|
pub fn get<T: IntoUrl>(url: T) -> ::Result<Response> {
|
||||||
Client::new()?
|
Client::new()?
|
||||||
.get(url)?
|
.get(url)?
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ impl RequestBuilder {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if the passed value cannot be serialized into
|
||||||
|
/// url encoded format
|
||||||
pub fn form<T: Serialize>(&mut self, form: &T) -> ::Result<&mut RequestBuilder> {
|
pub fn form<T: Serialize>(&mut self, form: &T) -> ::Result<&mut RequestBuilder> {
|
||||||
{
|
{
|
||||||
// check request_mut() before running serde
|
// check request_mut() before running serde
|
||||||
@@ -202,6 +207,11 @@ impl RequestBuilder {
|
|||||||
|
|
||||||
/// Build a `Request`, which can be inspected, modified and executed with
|
/// Build a `Request`, which can be inspected, modified and executed with
|
||||||
/// `Client::execute()`.
|
/// `Client::execute()`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This method consumes builder internal state. It panics on an attempt to
|
||||||
|
/// reuse already consumed builder.
|
||||||
pub fn build(&mut self) -> Request {
|
pub fn build(&mut self) -> Request {
|
||||||
self.request
|
self.request
|
||||||
.take()
|
.take()
|
||||||
@@ -209,6 +219,11 @@ impl RequestBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs the Request and sends it the target URL, returning a Response.
|
/// Constructs the Request and sends it the target URL, returning a Response.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if there was an error while sending request,
|
||||||
|
/// redirect loop was detected or redirect limit was exhausted.
|
||||||
pub fn send(&mut self) -> ::Result<::Response> {
|
pub fn send(&mut self) -> ::Result<::Response> {
|
||||||
let request = self.build();
|
let request = self.build();
|
||||||
self.client.execute(request)
|
self.client.execute(request)
|
||||||
|
|||||||
@@ -100,6 +100,13 @@ impl Response {
|
|||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever the response body is not in JSON format
|
||||||
|
/// or it cannot be properly deserialized to target type `T`. For more
|
||||||
|
/// details please see [`serde_json::from_reader`].
|
||||||
|
/// [`serde_json::from_reader`]: https://docs.serde.rs/serde_json/fn.from_reader.html
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn json<T: DeserializeOwned>(&mut self) -> ::Result<T> {
|
pub fn json<T: DeserializeOwned>(&mut self) -> ::Result<T> {
|
||||||
serde_json::from_reader(self).map_err(::error::from)
|
serde_json::from_reader(self).map_err(::error::from)
|
||||||
|
|||||||
Reference in New Issue
Block a user