use crate::call::CallEndpoint;
use crate::client::Client;
use crate::error::ClientError;
impl Client {
pub async fn call_streaming<E: CallEndpoint>(
&self,
args: E::Args,
) -> Result<reqwest::Response, ClientError> {
let path = E::build_path(&args);
let url = self.base_url.join(&path)?;
let method = E::method();
let mut request = self.inner.request(method, url);
if let Some(body_result) = E::request_body(&args) {
let body = body_result?;
request = request
.header(http::header::CONTENT_TYPE, "application/json")
.body(body);
}
for interceptor in &self.config.request_interceptors {
request = interceptor(request);
}
let response: reqwest::Response = match request.send().await {
Ok(resp) => resp,
Err(e) if e.is_timeout() => return Err(ClientError::Timeout),
Err(e) => return Err(ClientError::Request(e)),
};
for interceptor in &self.config.response_interceptors {
interceptor(&response);
}
let status = response.status();
if !status.is_success() {
let body = response.text().await.unwrap_or_default();
return Err(ClientError::Status { status, body });
}
Ok(response)
}
}