From f2364991250eddf70a1d77f39cb0e618dfa155d0 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 14 Apr 2023 22:54:54 +0200 Subject: [PATCH] Fix login errors not being detected --- src/services/my_autarco.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/services/my_autarco.rs b/src/services/my_autarco.rs index c665c82..8d8cccf 100644 --- a/src/services/my_autarco.rs +++ b/src/services/my_autarco.rs @@ -92,14 +92,17 @@ impl super::Service for Service { /// It mainly stores the acquired cookie in the client's cookie jar. The login credentials come /// from the loaded configuration (see [`Config`]). async fn login(&mut self) -> Result<()> { + let login_url = login_url().expect("valid login URL"); let params = [ ("username", &self.config.username), ("password", &self.config.password), ]; - let login_url = login_url().expect("valid login URL"); - self.client.post(login_url).form(¶ms).send().await?; - - Ok(()) + let response = self.client.post(login_url).form(¶ms).send().await?; + match response.error_for_status() { + Ok(_) => Ok(()), + Err(e) if e.status() == Some(StatusCode::UNAUTHORIZED) => Err(Error::NotAuthorized), + Err(e) => Err(e.into()), + } } /// Retrieves a status update from the API of the My Autarco site.