Skip to main content

fastly_api/apis/
logging_endpoint_errors_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`get_log_endpoint_errors`]
15#[derive(Clone, Debug, Default)]
16pub struct GetLogEndpointErrorsParams {
17    pub service_id: String,
18    pub from: Option<i64>,
19    pub to: Option<i64>,
20    pub filter_endpoint: Option<String>
21}
22
23
24/// struct for typed errors of method [`get_log_endpoint_errors`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum GetLogEndpointErrorsError {
28    Status401(crate::models::ErrorResponse),
29    Status403(crate::models::ErrorResponse),
30    Status404(crate::models::ErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Provides a near real-time stream of log errors through a hybrid short-polling model. A client should make an initial request using the `from` parameter to specify a start time. The `to` parameter should be used alongside the `from` parameter since the default bucket is 10 seconds.  For pagination, use the URLs provided in the Link header of the response. These contain updated `from` timestamps for retrieving the next or previous page of logs.  Defaults to `application/x-ndjson` format. Use `Accept: application/json` header to request standard JSON array format instead. 
36pub async fn get_log_endpoint_errors(configuration: &mut configuration::Configuration, params: GetLogEndpointErrorsParams) -> Result<String, Error<GetLogEndpointErrorsError>> {
37    let local_var_configuration = configuration;
38
39    // unbox the parameters
40    let service_id = params.service_id;
41    let from = params.from;
42    let to = params.to;
43    let filter_endpoint = params.filter_endpoint;
44
45
46    let local_var_client = &local_var_configuration.client;
47
48    let local_var_uri_str = format!("{}/observability/service/{service_id}/logging/errors", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
49    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
50
51    if let Some(ref local_var_str) = from {
52        local_var_req_builder = local_var_req_builder.query(&[("from", &local_var_str.to_string())]);
53    }
54    if let Some(ref local_var_str) = to {
55        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
56    }
57    if let Some(ref local_var_str) = filter_endpoint {
58        local_var_req_builder = local_var_req_builder.query(&[("filter[endpoint]", &local_var_str.to_string())]);
59    }
60    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
61        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
62    }
63    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
64        let local_var_key = local_var_apikey.key.clone();
65        let local_var_value = match local_var_apikey.prefix {
66            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
67            None => local_var_key,
68        };
69        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
70    };
71
72    let local_var_req = local_var_req_builder.build()?;
73    let local_var_resp = local_var_client.execute(local_var_req).await?;
74
75    if "GET" != "GET" && "GET" != "HEAD" {
76      let headers = local_var_resp.headers();
77      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
78          Some(v) => v.to_str().unwrap().parse().unwrap(),
79          None => configuration::DEFAULT_RATELIMIT,
80      };
81      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
82          Some(v) => v.to_str().unwrap().parse().unwrap(),
83          None => 0,
84      };
85    }
86
87    let local_var_status = local_var_resp.status();
88    let local_var_content = local_var_resp.text().await?;
89
90    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91        serde_json::from_str(&local_var_content).map_err(Error::from)
92    } else {
93        let local_var_entity: Option<GetLogEndpointErrorsError> = serde_json::from_str(&local_var_content).ok();
94        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95        Err(Error::ResponseError(local_var_error))
96    }
97}
98