fn handle_get_response(&self, resp: &reqwest::blocking::Response) -> Result<()> {
        let errors_remaining = header_as_number("x-esi-error-limit-remain", resp)?;
        let reset_seconds = header_as_number("x-esi-error-limit-reset", resp)?;
        let reset_window_at = Utc::now() + Duration::seconds(reset_seconds.into());
        let limit_present = resp.headers().get("x-esi-error-limited").is_some();
        let status_code = resp.status().as_u16();

        // Throttle request
        if limit_present || status_code == 420 || errors_remaining < 10 {
            self.0.write().locked_until = reset_window_at;
        }

        // Bail or continue depending on cause
        if limit_present {
            bail!(errors::ErrorKind::ESIErrorLimitError("Request blocked by ESI: Blocking header present. Throttling requests.".to_owned()));
        } else if status_code == 420 {
            bail!(errors::ErrorKind::ESIErrorLimitError("Request blocked by ESI: Server returned code 420. Throttling requests.".to_owned()));
        } else if errors_remaining < 10 {
            warn!("Remaining ESI error limit below watermark: Throttling requests.");
        } else if status_code != 200 && status_code != 403 {
            bail!(errors::ErrorKind::ESIErrorLimitError(format!("ESI returned error: {:?}", resp)));
        }

        Ok(())
    }
/// Inspect response for errors, especially for ESI-blocks
// FIXME: properly handle non-200 responses!
Inspect response for errors, especially for ESI-blocks
FIXME: properly handle non-200 responses!
Inspect response for errors especially for ESI - blocks FIXME : properly handle non - 200 responses!
fn handle_get_response(&self, resp: &reqwest::blocking::Response) -> Result<()> {
        let errors_remaining = header_as_number("x-esi-error-limit-remain", resp)?;
        let reset_seconds = header_as_number("x-esi-error-limit-reset", resp)?;
        let reset_window_at = Utc::now() + Duration::seconds(reset_seconds.into());
        let limit_present = resp.headers().get("x-esi-error-limited").is_some();
        let status_code = resp.status().as_u16();
        // Throttle request
        if limit_present || status_code == 420 || errors_remaining < 10 {
            self.0.write().locked_until = reset_window_at;
        }
        // Bail or continue depending on cause
        if limit_present {
            bail!(errors::ErrorKind::ESIErrorLimitError("Request blocked by ESI: Blocking header present. Throttling requests.".to_owned()));
        } else if status_code == 420 {
            bail!(errors::ErrorKind::ESIErrorLimitError("Request blocked by ESI: Server returned code 420. Throttling requests.".to_owned()));
        } else if errors_remaining < 10 {
            warn!("Remaining ESI error limit below watermark: Throttling requests.");
        } else if status_code != 200 && status_code != 403 {
            bail!(errors::ErrorKind::ESIErrorLimitError(format!("ESI returned error: {:?}", resp)));
        }
        Ok(())
    }
fn handle_get_response ( & self , resp : & reqwest :: blocking :: Response ) -> Result < ( ) > { let errors_remaining = header_as_number ( " " , resp ) ? ; let reset_seconds = header_as_number ( " " , resp ) ? ; let reset_window_at = Utc :: now ( ) + Duration :: seconds ( reset_seconds . into ( ) ) ; let limit_present = resp . headers ( ) . get ( " " ) . is_some ( ) ; let status_code = resp . status ( ) . as_u16 ( ) ; // Throttle request if limit_present || status_code == 420 || errors_remaining < 10 { self . 0 . write ( ) . locked_until = reset_window_at ; } // Bail or continue depending on cause if limit_present { bail ! ( errors ErrorKind ESIErrorLimitError ( " " to_owned ( ) ) ) ; } else if status_code == 420 { bail ! ( errors ErrorKind ESIErrorLimitError ( " " to_owned ( ) ) ) ; } else if errors_remaining < 10 { warn ! ( " " ) ; } else if status_code != 200 && status_code != 403 { bail ! ( errors ErrorKind ESIErrorLimitError ( format ( " " resp ) ) ) ; } Ok ( ( ) ) }
Inspect response for errors, especially for ESI-blocks
FIXME: properly handle non-200 responses!
Inspect response for errors especially for ESI - blocks FIXME : properly handle non - 200 responses!
&self
resp
&reqwest::blocking::Response
&self
resp
&reqwest::blocking::Response