tapis_apps/apis/
general_api.rs1use super::{ContentType, Error, configuration};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize, de::Error as _};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum HealthCheckError {
20 Status500(),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum ReadyCheckError {
28 Status503(),
29 UnknownValue(serde_json::Value),
30}
31
32pub async fn health_check(
34 configuration: &configuration::Configuration,
35) -> Result<models::RespBasic, Error<HealthCheckError>> {
36 let uri_str = format!("{}/v3/apps/healthcheck", configuration.base_path);
37 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39 if let Some(ref user_agent) = configuration.user_agent {
40 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41 }
42
43 let req = req_builder.build()?;
44 let resp = configuration.client.execute(req).await?;
45
46 let status = resp.status();
47 let content_type = resp
48 .headers()
49 .get("content-type")
50 .and_then(|v| v.to_str().ok())
51 .unwrap_or("application/octet-stream");
52 let content_type = super::ContentType::from(content_type);
53
54 if !status.is_client_error() && !status.is_server_error() {
55 let content = resp.text().await?;
56 match content_type {
57 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
58 ContentType::Text => Err(Error::from(serde_json::Error::custom(
59 "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
60 ))),
61 ContentType::Unsupported(unknown_type) => {
62 Err(Error::from(serde_json::Error::custom(format!(
63 "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
64 ))))
65 }
66 }
67 } else {
68 let content = resp.text().await?;
69 let entity: Option<HealthCheckError> = serde_json::from_str(&content).ok();
70 Err(Error::ResponseError(ResponseContent {
71 status,
72 content,
73 entity,
74 }))
75 }
76}
77
78pub async fn ready_check(
80 configuration: &configuration::Configuration,
81) -> Result<models::RespBasic, Error<ReadyCheckError>> {
82 let uri_str = format!("{}/v3/apps/readycheck", configuration.base_path);
83 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
84
85 if let Some(ref user_agent) = configuration.user_agent {
86 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87 }
88
89 let req = req_builder.build()?;
90 let resp = configuration.client.execute(req).await?;
91
92 let status = resp.status();
93 let content_type = resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let content_type = super::ContentType::from(content_type);
99
100 if !status.is_client_error() && !status.is_server_error() {
101 let content = resp.text().await?;
102 match content_type {
103 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104 ContentType::Text => Err(Error::from(serde_json::Error::custom(
105 "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
106 ))),
107 ContentType::Unsupported(unknown_type) => {
108 Err(Error::from(serde_json::Error::custom(format!(
109 "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
110 ))))
111 }
112 }
113 } else {
114 let content = resp.text().await?;
115 let entity: Option<ReadyCheckError> = serde_json::from_str(&content).ok();
116 Err(Error::ResponseError(ResponseContent {
117 status,
118 content,
119 entity,
120 }))
121 }
122}