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) } }