Fix login errors not being detected

This commit is contained in:
Paul van Tilburg 2023-04-14 22:54:54 +02:00
parent 02a4d1ca9b
commit f236499125
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 7 additions and 4 deletions

View File

@ -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(&params).send().await?;
Ok(())
let response = self.client.post(login_url).form(&params).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.