diff --git a/edu-sync/src/config.rs b/edu-sync/src/config.rs index 41fdd80..846da29 100644 --- a/edu-sync/src/config.rs +++ b/edu-sync/src/config.rs @@ -203,7 +203,8 @@ impl Config { if matches!(&string_result, Err(err) if err.kind() == ErrorKind::NotFound) { return Ok(Self::default()); } - toml::from_str(&string_result?).map_err(Into::into) + let config = toml::from_str(&string_result?)?; + Ok(config) } pub async fn write(&self) -> io::Result<()> { diff --git a/edu-ws/src/ajax.rs b/edu-ws/src/ajax.rs index 80f290d..7af78ac 100644 --- a/edu-ws/src/ajax.rs +++ b/edu-ws/src/ajax.rs @@ -74,11 +74,9 @@ impl Client { .post(self.ajax_url.clone()) .json(&requests) .send() - .await - .map_err(ReceiveError::HttpError)? + .await? .json::>, RequestError>>() - .await - .map_err(ReceiveError::HttpError)? + .await? .0? .into_iter() .map(Into::into) @@ -87,15 +85,17 @@ impl Client { } pub async fn get_config(&self) -> Result { - self.call_ajax(&[Request { - method: "tool_mobile_get_public_config", - arguments: HashMap::new(), - }]) - .await? - .into_iter() - .next() - .unwrap() - .map_err(Into::into) + let config = self + .call_ajax(&[Request { + method: "tool_mobile_get_public_config", + arguments: HashMap::new(), + }]) + .await? + .into_iter() + .next() + .unwrap()?; + + Ok(config) } } @@ -122,8 +122,8 @@ pub enum Error { pub enum ReceiveError { #[error(transparent)] RequestError(#[from] RequestError), - #[error("{0}")] - HttpError(reqwest::Error), + #[error(transparent)] + HttpError(#[from] reqwest::Error), } #[cfg(test)] diff --git a/edu-ws/src/token/login.rs b/edu-ws/src/token/login.rs index 571d079..8ba4e9d 100644 --- a/edu-ws/src/token/login.rs +++ b/edu-ws/src/token/login.rs @@ -61,7 +61,8 @@ impl Client { service: &'a str, } - self.http_client + let response = self + .http_client .post(self.login_url.clone()) .query(&LoginRequest { username, @@ -69,13 +70,12 @@ impl Client { service: "moodle_mobile_app", }) .send() - .await - .map_err(ReceiveError::HttpError)? + .await? .json::>() - .await - .map_err(ReceiveError::HttpError)? - .0 - .map_err(ReceiveError::LoginRequestError) + .await? + .0?; + + Ok(response) } } @@ -83,8 +83,8 @@ impl Client { pub enum ReceiveError { #[error(transparent)] LoginRequestError(#[from] Error), - #[error("{0}")] - HttpError(reqwest::Error), + #[error(transparent)] + HttpError(#[from] reqwest::Error), } pub type Result = result::Result; diff --git a/edu-ws/src/ws.rs b/edu-ws/src/ws.rs index 7d376cc..d25e571 100644 --- a/edu-ws/src/ws.rs +++ b/edu-ws/src/ws.rs @@ -31,8 +31,8 @@ pub enum Error { pub enum RequestError { #[error(transparent)] WsError(#[from] Error), - #[error("{0}")] - HttpError(reqwest::Error), + #[error(transparent)] + HttpError(#[from] reqwest::Error), } pub type Result = result::Result; @@ -94,7 +94,8 @@ impl Client { lang: Option<&'a str>, } - self.http_client + let ret = self + .http_client .post(self.ws_url.clone()) .query(&WsQuery { token: &self.token, @@ -107,13 +108,12 @@ impl Client { lang: self.lang.as_deref(), }) .send() - .await - .map_err(RequestError::HttpError)? + .await? .json::>() - .await - .map_err(RequestError::HttpError)? - .0 - .map_err(RequestError::WsError) + .await? + .0?; + + Ok(ret) } pub async fn get_info(&self) -> Result {