|
10 | 10 |
|
11 | 11 |
|
12 | 12 | use reqwest; |
13 | | -use serde::{Deserialize, Serialize}; |
| 13 | +use serde::{Deserialize, Serialize, de::Error as _}; |
14 | 14 | use crate::{apis::ResponseContent, models}; |
15 | | -use super::{Error, configuration}; |
| 15 | +use super::{Error, configuration, ContentType}; |
16 | 16 |
|
17 | 17 |
|
18 | 18 | /// struct for typed errors of method [`create_auto_tagging`] |
@@ -90,10 +90,20 @@ pub async fn create_auto_tagging(configuration: &configuration::Configuration, a |
90 | 90 | let resp = configuration.client.execute(req).await?; |
91 | 91 |
|
92 | 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); |
93 | 99 |
|
94 | 100 | if !status.is_client_error() && !status.is_server_error() { |
95 | 101 | let content = resp.text().await?; |
96 | | - serde_json::from_str(&content).map_err(Error::from) |
| 102 | + match content_type { |
| 103 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 104 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutoTaggingResource`"))), |
| 105 | + 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::AutoTaggingResource`")))), |
| 106 | + } |
97 | 107 | } else { |
98 | 108 | let content = resp.text().await?; |
99 | 109 | let entity: Option<CreateAutoTaggingError> = serde_json::from_str(&content).ok(); |
@@ -173,10 +183,20 @@ pub async fn get_auto_tagging_by_id(configuration: &configuration::Configuration |
173 | 183 | let resp = configuration.client.execute(req).await?; |
174 | 184 |
|
175 | 185 | let status = resp.status(); |
| 186 | + let content_type = resp |
| 187 | + .headers() |
| 188 | + .get("content-type") |
| 189 | + .and_then(|v| v.to_str().ok()) |
| 190 | + .unwrap_or("application/octet-stream"); |
| 191 | + let content_type = super::ContentType::from(content_type); |
176 | 192 |
|
177 | 193 | if !status.is_client_error() && !status.is_server_error() { |
178 | 194 | let content = resp.text().await?; |
179 | | - serde_json::from_str(&content).map_err(Error::from) |
| 195 | + match content_type { |
| 196 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 197 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutoTaggingResource`"))), |
| 198 | + 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::AutoTaggingResource`")))), |
| 199 | + } |
180 | 200 | } else { |
181 | 201 | let content = resp.text().await?; |
182 | 202 | let entity: Option<GetAutoTaggingByIdError> = serde_json::from_str(&content).ok(); |
@@ -213,10 +233,20 @@ pub async fn list_auto_tagging(configuration: &configuration::Configuration, ) - |
213 | 233 | let resp = configuration.client.execute(req).await?; |
214 | 234 |
|
215 | 235 | let status = resp.status(); |
| 236 | + let content_type = resp |
| 237 | + .headers() |
| 238 | + .get("content-type") |
| 239 | + .and_then(|v| v.to_str().ok()) |
| 240 | + .unwrap_or("application/octet-stream"); |
| 241 | + let content_type = super::ContentType::from(content_type); |
216 | 242 |
|
217 | 243 | if !status.is_client_error() && !status.is_server_error() { |
218 | 244 | let content = resp.text().await?; |
219 | | - serde_json::from_str(&content).map_err(Error::from) |
| 245 | + match content_type { |
| 246 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 247 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AutoTaggingResource>`"))), |
| 248 | + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::AutoTaggingResource>`")))), |
| 249 | + } |
220 | 250 | } else { |
221 | 251 | let content = resp.text().await?; |
222 | 252 | let entity: Option<ListAutoTaggingError> = serde_json::from_str(&content).ok(); |
@@ -253,10 +283,20 @@ pub async fn list_auto_tagging_schema(configuration: &configuration::Configurati |
253 | 283 | let resp = configuration.client.execute(req).await?; |
254 | 284 |
|
255 | 285 | let status = resp.status(); |
| 286 | + let content_type = resp |
| 287 | + .headers() |
| 288 | + .get("content-type") |
| 289 | + .and_then(|v| v.to_str().ok()) |
| 290 | + .unwrap_or("application/octet-stream"); |
| 291 | + let content_type = super::ContentType::from(content_type); |
256 | 292 |
|
257 | 293 | if !status.is_client_error() && !status.is_server_error() { |
258 | 294 | let content = resp.text().await?; |
259 | | - serde_json::from_str(&content).map_err(Error::from) |
| 295 | + match content_type { |
| 296 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 297 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AutoTaggingSpecificationSchema>`"))), |
| 298 | + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::AutoTaggingSpecificationSchema>`")))), |
| 299 | + } |
260 | 300 | } else { |
261 | 301 | let content = resp.text().await?; |
262 | 302 | let entity: Option<ListAutoTaggingSchemaError> = serde_json::from_str(&content).ok(); |
@@ -297,10 +337,20 @@ pub async fn update_auto_tagging(configuration: &configuration::Configuration, i |
297 | 337 | let resp = configuration.client.execute(req).await?; |
298 | 338 |
|
299 | 339 | let status = resp.status(); |
| 340 | + let content_type = resp |
| 341 | + .headers() |
| 342 | + .get("content-type") |
| 343 | + .and_then(|v| v.to_str().ok()) |
| 344 | + .unwrap_or("application/octet-stream"); |
| 345 | + let content_type = super::ContentType::from(content_type); |
300 | 346 |
|
301 | 347 | if !status.is_client_error() && !status.is_server_error() { |
302 | 348 | let content = resp.text().await?; |
303 | | - serde_json::from_str(&content).map_err(Error::from) |
| 349 | + match content_type { |
| 350 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 351 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutoTaggingResource`"))), |
| 352 | + 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::AutoTaggingResource`")))), |
| 353 | + } |
304 | 354 | } else { |
305 | 355 | let content = resp.text().await?; |
306 | 356 | let entity: Option<UpdateAutoTaggingError> = serde_json::from_str(&content).ok(); |
|
0 commit comments