From 60870fc45822c0b98f39beea65459d87d98a5aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 9 Sep 2025 16:34:35 +0100 Subject: [PATCH] another restoration --- common/http-api-client/src/lib.rs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 1a8f97fb7b..69d61b9daf 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -297,6 +297,13 @@ pub enum HttpClientError { #[error("request failed with error message: {0}")] GenericRequestFailure(String), + #[deprecated(note = "use another more strongly typed variant")] + #[error("there was an issue with the REST request: {source}")] + ReqwestClientError { + #[from] + source: reqwest::Error, + }, + #[error("failed to parse {raw} as a valid URL: {source}")] MalformedUrl { raw: String, @@ -386,7 +393,32 @@ pub enum HttpClientError { } #[allow(missing_docs)] +#[allow(deprecated)] impl HttpClientError { + /// Returns true if the error is a timeout. + pub fn is_timeout(&self) -> bool { + match self { + HttpClientError::ReqwestClientError { source } => source.is_timeout(), + HttpClientError::RequestSendFailure { source, .. } => source.0.is_timeout(), + HttpClientError::ResponseReadFailure { source, .. } => source.0.is_timeout(), + #[cfg(target_arch = "wasm32")] + HttpClientError::RequestTimeout => true, + _ => false, + } + } + + /// Returns the HTTP status code if available. + pub fn status_code(&self) -> Option { + match self { + HttpClientError::ResponseReadFailure { status, .. } => Some(*status), + HttpClientError::RequestFailure { status, .. } => Some(*status), + HttpClientError::EmptyResponse { status, .. } => Some(*status), + HttpClientError::EndpointFailure { status, .. } => Some(*status), + HttpClientError::EndpointFailure { status, .. } => Some(*status), + _ => None, + } + } + pub fn reqwest_client_build_error(source: reqwest::Error) -> Self { HttpClientError::ReqwestBuildError { source } }