motis_openapi_sdk/apis/
debug_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum TransfersError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn transfers(configuration: &configuration::Configuration, id: &str) -> Result<models::Transfers200Response, Error<TransfersError>> {
27 let p_query_id = id;
29
30 let uri_str = format!("{}/api/debug/transfers", configuration.base_path);
31 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
32
33 req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
34 if let Some(ref user_agent) = configuration.user_agent {
35 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
36 }
37
38 let req = req_builder.build()?;
39 let resp = configuration.client.execute(req).await?;
40
41 let status = resp.status();
42 let content_type = resp
43 .headers()
44 .get("content-type")
45 .and_then(|v| v.to_str().ok())
46 .unwrap_or("application/octet-stream");
47 let content_type = super::ContentType::from(content_type);
48
49 if !status.is_client_error() && !status.is_server_error() {
50 let content = resp.text().await?;
51 match content_type {
52 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
53 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Transfers200Response`"))),
54 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Transfers200Response`")))),
55 }
56 } else {
57 let content = resp.text().await?;
58 let entity: Option<TransfersError> = serde_json::from_str(&content).ok();
59 Err(Error::ResponseError(ResponseContent { status, content, entity }))
60 }
61}
62