From ec3499763ba7bce53a970c678eb801030a164d63 Mon Sep 17 00:00:00 2001 From: Maxime Augier Date: Fri, 2 Aug 2024 11:31:18 +0200 Subject: [PATCH] Box the ureq errors --- src/api.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api.rs b/src/api.rs index e2c3d02..f61aee2 100644 --- a/src/api.rs +++ b/src/api.rs @@ -194,7 +194,7 @@ pub enum ApiError { IO(#[from] io::Error), #[error("ureq")] - Ureq(#[from] ureq::Error), + Ureq(#[source] Box), #[error("unexpected data: {1} when processing {0}")] UnexpectedData(serde_json::Value, serde_json::Error), @@ -206,6 +206,12 @@ pub enum ApiError { FormatError(#[from] chrono::ParseError) } +impl From for ApiError { + fn from(value: ureq::Error) -> Self { + ApiError::Ureq(Box::new(value)) + } +} + trait JsonExplicitError { fn into_json_with_error(self) -> Result; } @@ -299,7 +305,10 @@ impl Context { fn maybe_get(&mut self, path: &str) -> Result, ApiError> { match self.get(path) { Ok(r) => Ok(Some(r)), - Err(ApiError::Ureq(ureq::Error::Status(404, _))) => Ok(None), + Err(ApiError::Ureq(e)) => match &*e { + ureq::Error::Status(404, _ ) => Ok(None), + _ => Err(ApiError::Ureq(e)) + }, Err(other) => Err(other) } }