adguard_flm/io/http/
error.rs

1use reqwest::StatusCode;
2
3/// Common HTTP client errors enum
4#[non_exhaustive]
5#[derive(Debug, thiserror::Error, PartialEq)]
6pub enum HttpClientError {
7    /// Network error
8    #[error("Network error: {0}")]
9    NetworkError(String),
10
11    /// Deserialization/Body reading failed
12    #[error("Body recovery failed: {0}")]
13    BodyRecoveryFailed(String),
14
15    /// Should have only 200 OK successful status code. e.g. 204 would be an error.
16    #[error("Expected strictly 200 status code, but {0} given for url: {1}")]
17    Strict200Response(u16, String),
18}
19
20impl HttpClientError {
21    #[inline]
22    pub(crate) fn make_network(error: reqwest::Error) -> Self {
23        Self::NetworkError(error.to_string())
24    }
25
26    #[inline]
27    pub(crate) fn make_body_recovery(error: reqwest::Error) -> Self {
28        Self::BodyRecoveryFailed(error.to_string())
29    }
30
31    #[inline]
32    pub(crate) fn make_only_200_strict(actual_code: StatusCode, url: String) -> Self {
33        Self::Strict200Response(actual_code.as_u16(), url)
34    }
35}