launchdarkly_server_sdk/
reqwest.rs
1use hyper::StatusCode;
2
3pub fn is_http_error_recoverable(status: u16) -> bool {
4 if let Ok(status) = StatusCode::from_u16(status) {
5 if !status.is_client_error() {
6 return true;
7 }
8
9 return matches!(
10 status,
11 StatusCode::BAD_REQUEST | StatusCode::REQUEST_TIMEOUT | StatusCode::TOO_MANY_REQUESTS
12 );
13 }
14
15 warn!("Unable to determine if status code is recoverable");
16 false
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22 use hyper::StatusCode;
23 use test_case::test_case;
24
25 #[test_case("130.65331632653061", 130.65331632653061)]
26 #[test_case("130.65331632653062", 130.65331632653061)]
27 #[test_case("130.65331632653063", 130.65331632653064)]
28 fn json_float_serialization_matches_go(float_as_string: &str, expected: f64) {
29 let parsed: f64 = serde_json::from_str(float_as_string).unwrap();
30 assert_eq!(expected, parsed);
31 }
32
33 #[test_case(StatusCode::CONTINUE, true)]
34 #[test_case(StatusCode::OK, true)]
35 #[test_case(StatusCode::MULTIPLE_CHOICES, true)]
36 #[test_case(StatusCode::BAD_REQUEST, true)]
37 #[test_case(StatusCode::UNAUTHORIZED, false)]
38 #[test_case(StatusCode::REQUEST_TIMEOUT, true)]
39 #[test_case(StatusCode::CONFLICT, false)]
40 #[test_case(StatusCode::TOO_MANY_REQUESTS, true)]
41 #[test_case(StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE, false)]
42 #[test_case(StatusCode::INTERNAL_SERVER_ERROR, true)]
43 fn can_determine_recoverable_errors(status: StatusCode, is_recoverable: bool) {
44 assert_eq!(is_recoverable, is_http_error_recoverable(status.as_u16()));
45 }
46}