1use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7 write::{GzEncoder, ZlibEncoder},
8 Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct ListEventsOptionalParams {
19 pub filter_query: Option<String>,
21 pub filter_from: Option<String>,
23 pub filter_to: Option<String>,
25 pub sort: Option<crate::datadogV2::model::EventsSort>,
27 pub page_cursor: Option<String>,
29 pub page_limit: Option<i32>,
31}
32
33impl ListEventsOptionalParams {
34 pub fn filter_query(mut self, value: String) -> Self {
36 self.filter_query = Some(value);
37 self
38 }
39 pub fn filter_from(mut self, value: String) -> Self {
41 self.filter_from = Some(value);
42 self
43 }
44 pub fn filter_to(mut self, value: String) -> Self {
46 self.filter_to = Some(value);
47 self
48 }
49 pub fn sort(mut self, value: crate::datadogV2::model::EventsSort) -> Self {
51 self.sort = Some(value);
52 self
53 }
54 pub fn page_cursor(mut self, value: String) -> Self {
56 self.page_cursor = Some(value);
57 self
58 }
59 pub fn page_limit(mut self, value: i32) -> Self {
61 self.page_limit = Some(value);
62 self
63 }
64}
65
66#[non_exhaustive]
68#[derive(Clone, Default, Debug)]
69pub struct SearchEventsOptionalParams {
70 pub body: Option<crate::datadogV2::model::EventsListRequest>,
71}
72
73impl SearchEventsOptionalParams {
74 pub fn body(mut self, value: crate::datadogV2::model::EventsListRequest) -> Self {
75 self.body = Some(value);
76 self
77 }
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum CreateEventError {
84 JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
85 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
86 UnknownValue(serde_json::Value),
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum GetEventError {
93 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
94 UnknownValue(serde_json::Value),
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum ListEventsError {
101 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
102 UnknownValue(serde_json::Value),
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(untagged)]
108pub enum SearchEventsError {
109 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
110 UnknownValue(serde_json::Value),
111}
112
113#[derive(Debug, Clone)]
117pub struct EventsAPI {
118 config: datadog::Configuration,
119 client: reqwest_middleware::ClientWithMiddleware,
120}
121
122impl Default for EventsAPI {
123 fn default() -> Self {
124 Self::with_config(datadog::Configuration::default())
125 }
126}
127
128impl EventsAPI {
129 pub fn new() -> Self {
130 Self::default()
131 }
132 pub fn with_config(config: datadog::Configuration) -> Self {
133 let mut reqwest_client_builder = reqwest::Client::builder();
134
135 if let Some(proxy_url) = &config.proxy_url {
136 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
137 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
138 }
139
140 let mut middleware_client_builder =
141 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
142
143 if config.enable_retry {
144 struct RetryableStatus;
145 impl reqwest_retry::RetryableStrategy for RetryableStatus {
146 fn handle(
147 &self,
148 res: &Result<reqwest::Response, reqwest_middleware::Error>,
149 ) -> Option<reqwest_retry::Retryable> {
150 match res {
151 Ok(success) => reqwest_retry::default_on_request_success(success),
152 Err(_) => None,
153 }
154 }
155 }
156 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
157 .build_with_max_retries(config.max_retries);
158
159 let retry_middleware =
160 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
161 backoff_policy,
162 RetryableStatus,
163 );
164
165 middleware_client_builder = middleware_client_builder.with(retry_middleware);
166 }
167
168 let client = middleware_client_builder.build();
169
170 Self { config, client }
171 }
172
173 pub fn with_client_and_config(
174 config: datadog::Configuration,
175 client: reqwest_middleware::ClientWithMiddleware,
176 ) -> Self {
177 Self { config, client }
178 }
179
180 pub async fn create_event(
190 &self,
191 body: crate::datadogV2::model::EventCreateRequestPayload,
192 ) -> Result<crate::datadogV2::model::EventCreateResponsePayload, datadog::Error<CreateEventError>>
193 {
194 match self.create_event_with_http_info(body).await {
195 Ok(response_content) => {
196 if let Some(e) = response_content.entity {
197 Ok(e)
198 } else {
199 Err(datadog::Error::Serde(serde::de::Error::custom(
200 "response content was None",
201 )))
202 }
203 }
204 Err(err) => Err(err),
205 }
206 }
207
208 pub async fn create_event_with_http_info(
218 &self,
219 body: crate::datadogV2::model::EventCreateRequestPayload,
220 ) -> Result<
221 datadog::ResponseContent<crate::datadogV2::model::EventCreateResponsePayload>,
222 datadog::Error<CreateEventError>,
223 > {
224 let local_configuration = &self.config;
225 let operation_id = "v2.create_event";
226
227 let local_client = &self.client;
228
229 let local_uri_str = format!(
230 "{}/api/v2/events",
231 local_configuration.get_operation_host(operation_id)
232 );
233 let mut local_req_builder =
234 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
235
236 let mut headers = HeaderMap::new();
238 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
239 headers.insert("Accept", HeaderValue::from_static("application/json"));
240
241 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
243 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
244 Err(e) => {
245 log::warn!("Failed to parse user agent header: {e}, falling back to default");
246 headers.insert(
247 reqwest::header::USER_AGENT,
248 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
249 )
250 }
251 };
252
253 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
255 headers.insert(
256 "DD-API-KEY",
257 HeaderValue::from_str(local_key.key.as_str())
258 .expect("failed to parse DD-API-KEY header"),
259 );
260 };
261 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
262 headers.insert(
263 "DD-APPLICATION-KEY",
264 HeaderValue::from_str(local_key.key.as_str())
265 .expect("failed to parse DD-APPLICATION-KEY header"),
266 );
267 };
268
269 let output = Vec::new();
271 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
272 if body.serialize(&mut ser).is_ok() {
273 if let Some(content_encoding) = headers.get("Content-Encoding") {
274 match content_encoding.to_str().unwrap_or_default() {
275 "gzip" => {
276 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
277 let _ = enc.write_all(ser.into_inner().as_slice());
278 match enc.finish() {
279 Ok(buf) => {
280 local_req_builder = local_req_builder.body(buf);
281 }
282 Err(e) => return Err(datadog::Error::Io(e)),
283 }
284 }
285 "deflate" => {
286 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
287 let _ = enc.write_all(ser.into_inner().as_slice());
288 match enc.finish() {
289 Ok(buf) => {
290 local_req_builder = local_req_builder.body(buf);
291 }
292 Err(e) => return Err(datadog::Error::Io(e)),
293 }
294 }
295 "zstd1" => {
296 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
297 let _ = enc.write_all(ser.into_inner().as_slice());
298 match enc.finish() {
299 Ok(buf) => {
300 local_req_builder = local_req_builder.body(buf);
301 }
302 Err(e) => return Err(datadog::Error::Io(e)),
303 }
304 }
305 _ => {
306 local_req_builder = local_req_builder.body(ser.into_inner());
307 }
308 }
309 } else {
310 local_req_builder = local_req_builder.body(ser.into_inner());
311 }
312 }
313
314 local_req_builder = local_req_builder.headers(headers);
315 let local_req = local_req_builder.build()?;
316 log::debug!("request content: {:?}", local_req.body());
317 let local_resp = local_client.execute(local_req).await?;
318
319 let local_status = local_resp.status();
320 let local_content = local_resp.text().await?;
321 log::debug!("response content: {}", local_content);
322
323 if !local_status.is_client_error() && !local_status.is_server_error() {
324 match serde_json::from_str::<crate::datadogV2::model::EventCreateResponsePayload>(
325 &local_content,
326 ) {
327 Ok(e) => {
328 return Ok(datadog::ResponseContent {
329 status: local_status,
330 content: local_content,
331 entity: Some(e),
332 })
333 }
334 Err(e) => return Err(datadog::Error::Serde(e)),
335 };
336 } else {
337 let local_entity: Option<CreateEventError> = serde_json::from_str(&local_content).ok();
338 let local_error = datadog::ResponseContent {
339 status: local_status,
340 content: local_content,
341 entity: local_entity,
342 };
343 Err(datadog::Error::ResponseError(local_error))
344 }
345 }
346
347 pub async fn get_event(
349 &self,
350 event_id: String,
351 ) -> Result<crate::datadogV2::model::V2EventResponse, datadog::Error<GetEventError>> {
352 match self.get_event_with_http_info(event_id).await {
353 Ok(response_content) => {
354 if let Some(e) = response_content.entity {
355 Ok(e)
356 } else {
357 Err(datadog::Error::Serde(serde::de::Error::custom(
358 "response content was None",
359 )))
360 }
361 }
362 Err(err) => Err(err),
363 }
364 }
365
366 pub async fn get_event_with_http_info(
368 &self,
369 event_id: String,
370 ) -> Result<
371 datadog::ResponseContent<crate::datadogV2::model::V2EventResponse>,
372 datadog::Error<GetEventError>,
373 > {
374 let local_configuration = &self.config;
375 let operation_id = "v2.get_event";
376
377 let local_client = &self.client;
378
379 let local_uri_str = format!(
380 "{}/api/v2/events/{event_id}",
381 local_configuration.get_operation_host(operation_id),
382 event_id = datadog::urlencode(event_id)
383 );
384 let mut local_req_builder =
385 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
386
387 let mut headers = HeaderMap::new();
389 headers.insert("Accept", HeaderValue::from_static("application/json"));
390
391 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
393 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
394 Err(e) => {
395 log::warn!("Failed to parse user agent header: {e}, falling back to default");
396 headers.insert(
397 reqwest::header::USER_AGENT,
398 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
399 )
400 }
401 };
402
403 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
405 headers.insert(
406 "DD-API-KEY",
407 HeaderValue::from_str(local_key.key.as_str())
408 .expect("failed to parse DD-API-KEY header"),
409 );
410 };
411 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
412 headers.insert(
413 "DD-APPLICATION-KEY",
414 HeaderValue::from_str(local_key.key.as_str())
415 .expect("failed to parse DD-APPLICATION-KEY header"),
416 );
417 };
418
419 local_req_builder = local_req_builder.headers(headers);
420 let local_req = local_req_builder.build()?;
421 log::debug!("request content: {:?}", local_req.body());
422 let local_resp = local_client.execute(local_req).await?;
423
424 let local_status = local_resp.status();
425 let local_content = local_resp.text().await?;
426 log::debug!("response content: {}", local_content);
427
428 if !local_status.is_client_error() && !local_status.is_server_error() {
429 match serde_json::from_str::<crate::datadogV2::model::V2EventResponse>(&local_content) {
430 Ok(e) => {
431 return Ok(datadog::ResponseContent {
432 status: local_status,
433 content: local_content,
434 entity: Some(e),
435 })
436 }
437 Err(e) => return Err(datadog::Error::Serde(e)),
438 };
439 } else {
440 let local_entity: Option<GetEventError> = serde_json::from_str(&local_content).ok();
441 let local_error = datadog::ResponseContent {
442 status: local_status,
443 content: local_content,
444 entity: local_entity,
445 };
446 Err(datadog::Error::ResponseError(local_error))
447 }
448 }
449
450 pub async fn list_events(
455 &self,
456 params: ListEventsOptionalParams,
457 ) -> Result<crate::datadogV2::model::EventsListResponse, datadog::Error<ListEventsError>> {
458 match self.list_events_with_http_info(params).await {
459 Ok(response_content) => {
460 if let Some(e) = response_content.entity {
461 Ok(e)
462 } else {
463 Err(datadog::Error::Serde(serde::de::Error::custom(
464 "response content was None",
465 )))
466 }
467 }
468 Err(err) => Err(err),
469 }
470 }
471
472 pub fn list_events_with_pagination(
473 &self,
474 mut params: ListEventsOptionalParams,
475 ) -> impl Stream<
476 Item = Result<crate::datadogV2::model::EventResponse, datadog::Error<ListEventsError>>,
477 > + '_ {
478 try_stream! {
479 let mut page_size: i32 = 10;
480 if params.page_limit.is_none() {
481 params.page_limit = Some(page_size);
482 } else {
483 page_size = params.page_limit.unwrap().clone();
484 }
485 loop {
486 let resp = self.list_events(params.clone()).await?;
487 let Some(data) = resp.data else { break };
488
489 let r = data;
490 let count = r.len();
491 for team in r {
492 yield team;
493 }
494
495 if count < page_size as usize {
496 break;
497 }
498 let Some(meta) = resp.meta else { break };
499 let Some(page) = meta.page else { break };
500 let Some(after) = page.after else { break };
501
502 params.page_cursor = Some(after);
503 }
504 }
505 }
506
507 pub async fn list_events_with_http_info(
512 &self,
513 params: ListEventsOptionalParams,
514 ) -> Result<
515 datadog::ResponseContent<crate::datadogV2::model::EventsListResponse>,
516 datadog::Error<ListEventsError>,
517 > {
518 let local_configuration = &self.config;
519 let operation_id = "v2.list_events";
520
521 let filter_query = params.filter_query;
523 let filter_from = params.filter_from;
524 let filter_to = params.filter_to;
525 let sort = params.sort;
526 let page_cursor = params.page_cursor;
527 let page_limit = params.page_limit;
528
529 let local_client = &self.client;
530
531 let local_uri_str = format!(
532 "{}/api/v2/events",
533 local_configuration.get_operation_host(operation_id)
534 );
535 let mut local_req_builder =
536 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
537
538 if let Some(ref local_query_param) = filter_query {
539 local_req_builder =
540 local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]);
541 };
542 if let Some(ref local_query_param) = filter_from {
543 local_req_builder =
544 local_req_builder.query(&[("filter[from]", &local_query_param.to_string())]);
545 };
546 if let Some(ref local_query_param) = filter_to {
547 local_req_builder =
548 local_req_builder.query(&[("filter[to]", &local_query_param.to_string())]);
549 };
550 if let Some(ref local_query_param) = sort {
551 local_req_builder =
552 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
553 };
554 if let Some(ref local_query_param) = page_cursor {
555 local_req_builder =
556 local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
557 };
558 if let Some(ref local_query_param) = page_limit {
559 local_req_builder =
560 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
561 };
562
563 let mut headers = HeaderMap::new();
565 headers.insert("Accept", HeaderValue::from_static("application/json"));
566
567 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
569 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
570 Err(e) => {
571 log::warn!("Failed to parse user agent header: {e}, falling back to default");
572 headers.insert(
573 reqwest::header::USER_AGENT,
574 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
575 )
576 }
577 };
578
579 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
581 headers.insert(
582 "DD-API-KEY",
583 HeaderValue::from_str(local_key.key.as_str())
584 .expect("failed to parse DD-API-KEY header"),
585 );
586 };
587 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
588 headers.insert(
589 "DD-APPLICATION-KEY",
590 HeaderValue::from_str(local_key.key.as_str())
591 .expect("failed to parse DD-APPLICATION-KEY header"),
592 );
593 };
594
595 local_req_builder = local_req_builder.headers(headers);
596 let local_req = local_req_builder.build()?;
597 log::debug!("request content: {:?}", local_req.body());
598 let local_resp = local_client.execute(local_req).await?;
599
600 let local_status = local_resp.status();
601 let local_content = local_resp.text().await?;
602 log::debug!("response content: {}", local_content);
603
604 if !local_status.is_client_error() && !local_status.is_server_error() {
605 match serde_json::from_str::<crate::datadogV2::model::EventsListResponse>(
606 &local_content,
607 ) {
608 Ok(e) => {
609 return Ok(datadog::ResponseContent {
610 status: local_status,
611 content: local_content,
612 entity: Some(e),
613 })
614 }
615 Err(e) => return Err(datadog::Error::Serde(e)),
616 };
617 } else {
618 let local_entity: Option<ListEventsError> = serde_json::from_str(&local_content).ok();
619 let local_error = datadog::ResponseContent {
620 status: local_status,
621 content: local_content,
622 entity: local_entity,
623 };
624 Err(datadog::Error::ResponseError(local_error))
625 }
626 }
627
628 pub async fn search_events(
633 &self,
634 params: SearchEventsOptionalParams,
635 ) -> Result<crate::datadogV2::model::EventsListResponse, datadog::Error<SearchEventsError>>
636 {
637 match self.search_events_with_http_info(params).await {
638 Ok(response_content) => {
639 if let Some(e) = response_content.entity {
640 Ok(e)
641 } else {
642 Err(datadog::Error::Serde(serde::de::Error::custom(
643 "response content was None",
644 )))
645 }
646 }
647 Err(err) => Err(err),
648 }
649 }
650
651 pub fn search_events_with_pagination(
652 &self,
653 mut params: SearchEventsOptionalParams,
654 ) -> impl Stream<
655 Item = Result<crate::datadogV2::model::EventResponse, datadog::Error<SearchEventsError>>,
656 > + '_ {
657 try_stream! {
658 let mut page_size: i32 = 10;
659 if params.body.is_none() {
660 params.body = Some(crate::datadogV2::model::EventsListRequest::new());
661 }
662 if params.body.as_ref().unwrap().page.is_none() {
663 params.body.as_mut().unwrap().page = Some(crate::datadogV2::model::EventsRequestPage::new());
664 }
665 if params.body.as_ref().unwrap().page.as_ref().unwrap().limit.is_none() {
666 params.body.as_mut().unwrap().page.as_mut().unwrap().limit = Some(page_size);
667 } else {
668 page_size = params.body.as_ref().unwrap().page.as_ref().unwrap().limit.unwrap().clone();
669 }
670 loop {
671 let resp = self.search_events(params.clone()).await?;
672 let Some(data) = resp.data else { break };
673
674 let r = data;
675 let count = r.len();
676 for team in r {
677 yield team;
678 }
679
680 if count < page_size as usize {
681 break;
682 }
683 let Some(meta) = resp.meta else { break };
684 let Some(page) = meta.page else { break };
685 let Some(after) = page.after else { break };
686
687 params.body.as_mut().unwrap().page.as_mut().unwrap().cursor = Some(after);
688 }
689 }
690 }
691
692 pub async fn search_events_with_http_info(
697 &self,
698 params: SearchEventsOptionalParams,
699 ) -> Result<
700 datadog::ResponseContent<crate::datadogV2::model::EventsListResponse>,
701 datadog::Error<SearchEventsError>,
702 > {
703 let local_configuration = &self.config;
704 let operation_id = "v2.search_events";
705
706 let body = params.body;
708
709 let local_client = &self.client;
710
711 let local_uri_str = format!(
712 "{}/api/v2/events/search",
713 local_configuration.get_operation_host(operation_id)
714 );
715 let mut local_req_builder =
716 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
717
718 let mut headers = HeaderMap::new();
720 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
721 headers.insert("Accept", HeaderValue::from_static("application/json"));
722
723 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
725 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
726 Err(e) => {
727 log::warn!("Failed to parse user agent header: {e}, falling back to default");
728 headers.insert(
729 reqwest::header::USER_AGENT,
730 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
731 )
732 }
733 };
734
735 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
737 headers.insert(
738 "DD-API-KEY",
739 HeaderValue::from_str(local_key.key.as_str())
740 .expect("failed to parse DD-API-KEY header"),
741 );
742 };
743 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
744 headers.insert(
745 "DD-APPLICATION-KEY",
746 HeaderValue::from_str(local_key.key.as_str())
747 .expect("failed to parse DD-APPLICATION-KEY header"),
748 );
749 };
750
751 let output = Vec::new();
753 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
754 if body.serialize(&mut ser).is_ok() {
755 if let Some(content_encoding) = headers.get("Content-Encoding") {
756 match content_encoding.to_str().unwrap_or_default() {
757 "gzip" => {
758 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
759 let _ = enc.write_all(ser.into_inner().as_slice());
760 match enc.finish() {
761 Ok(buf) => {
762 local_req_builder = local_req_builder.body(buf);
763 }
764 Err(e) => return Err(datadog::Error::Io(e)),
765 }
766 }
767 "deflate" => {
768 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
769 let _ = enc.write_all(ser.into_inner().as_slice());
770 match enc.finish() {
771 Ok(buf) => {
772 local_req_builder = local_req_builder.body(buf);
773 }
774 Err(e) => return Err(datadog::Error::Io(e)),
775 }
776 }
777 "zstd1" => {
778 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
779 let _ = enc.write_all(ser.into_inner().as_slice());
780 match enc.finish() {
781 Ok(buf) => {
782 local_req_builder = local_req_builder.body(buf);
783 }
784 Err(e) => return Err(datadog::Error::Io(e)),
785 }
786 }
787 _ => {
788 local_req_builder = local_req_builder.body(ser.into_inner());
789 }
790 }
791 } else {
792 local_req_builder = local_req_builder.body(ser.into_inner());
793 }
794 }
795
796 local_req_builder = local_req_builder.headers(headers);
797 let local_req = local_req_builder.build()?;
798 log::debug!("request content: {:?}", local_req.body());
799 let local_resp = local_client.execute(local_req).await?;
800
801 let local_status = local_resp.status();
802 let local_content = local_resp.text().await?;
803 log::debug!("response content: {}", local_content);
804
805 if !local_status.is_client_error() && !local_status.is_server_error() {
806 match serde_json::from_str::<crate::datadogV2::model::EventsListResponse>(
807 &local_content,
808 ) {
809 Ok(e) => {
810 return Ok(datadog::ResponseContent {
811 status: local_status,
812 content: local_content,
813 entity: Some(e),
814 })
815 }
816 Err(e) => return Err(datadog::Error::Serde(e)),
817 };
818 } else {
819 let local_entity: Option<SearchEventsError> = serde_json::from_str(&local_content).ok();
820 let local_error = datadog::ResponseContent {
821 status: local_status,
822 content: local_content,
823 entity: local_entity,
824 };
825 Err(datadog::Error::ResponseError(local_error))
826 }
827 }
828}