p7m_phone/apis/
internal_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 CheckPendingBlocksError {
22 UnknownValue(serde_json::Value),
23}
24
25
26pub async fn check_pending_blocks(configuration: &configuration::Configuration, ) -> Result<String, Error<CheckPendingBlocksError>> {
27
28 let uri_str = format!("{}/block/check_pending", configuration.base_path);
29 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
30
31 if let Some(ref user_agent) = configuration.user_agent {
32 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
33 }
34
35 let req = req_builder.build()?;
36 let resp = configuration.client.execute(req).await?;
37
38 let status = resp.status();
39 let content_type = resp
40 .headers()
41 .get("content-type")
42 .and_then(|v| v.to_str().ok())
43 .unwrap_or("application/octet-stream");
44 let content_type = super::ContentType::from(content_type);
45
46 if !status.is_client_error() && !status.is_server_error() {
47 let content = resp.text().await?;
48 match content_type {
49 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
50 ContentType::Text => return Ok(content),
51 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
52 }
53 } else {
54 let content = resp.text().await?;
55 let entity: Option<CheckPendingBlocksError> = serde_json::from_str(&content).ok();
56 Err(Error::ResponseError(ResponseContent { status, content, entity }))
57 }
58}
59