diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-05-28 03:12:09 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-05-28 03:19:45 -0400 |
commit | 3ab2da1595da8b1b596f256a26c9e65ab35bc24c (patch) | |
tree | 5400a00a8c341582a7d93f9d06bce732f9c81d39 /src/api.rs | |
parent | 3efe6a2b304c0c63bd2ce86adcd23a3647634008 (diff) | |
download | rbw-3ab2da1595da8b1b596f256a26c9e65ab35bc24c.tar.gz rbw-3ab2da1595da8b1b596f256a26c9e65ab35bc24c.zip |
display the server's error message for incorrect password
Diffstat (limited to 'src/api.rs')
-rw-r--r-- | src/api.rs | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -901,24 +901,26 @@ fn classify_login_error(error_res: &ConnectErrorRes, code: u16) -> Error { match error_res.error.as_str() { "invalid_grant" => match error_res.error_description.as_str() { "invalid_username_or_password" => { - return Error::IncorrectPassword; + if let Some(error_model) = error_res.error_model.as_ref() { + let message = error_model.message.as_str().to_string(); + return Error::IncorrectPassword { message }; + } } "Two factor required." => { - match error_res.two_factor_providers.as_ref() { - Some(providers) => { - let providers: Result<_> = providers - .iter() - .copied() - .map(std::convert::TryInto::try_into) - .collect(); - return match providers { - Ok(providers) => { - Error::TwoFactorRequired { providers } - } - Err(e) => e, - }; - } - _ => {} + if let Some(providers) = + error_res.two_factor_providers.as_ref() + { + let providers: Result<_> = providers + .iter() + .copied() + .map(std::convert::TryInto::try_into) + .collect(); + return match providers { + Ok(providers) => { + Error::TwoFactorRequired { providers } + } + Err(e) => e, + }; } } _ => {} @@ -928,16 +930,17 @@ fn classify_login_error(error_res: &ConnectErrorRes, code: u16) -> Error { // this case, for some reason if error_res.error_description == "" { if let Some(error_model) = error_res.error_model.as_ref() { - match error_model.message.as_str() { + let message = error_model.message.as_str().to_string(); + match message.as_str() { "Username or password is incorrect. Try again" | "TOTP code is not a number" => { - return Error::IncorrectPassword; + return Error::IncorrectPassword { message }; } s => { if s.starts_with( "Invalid TOTP code! Server time: ", ) { - return Error::IncorrectPassword; + return Error::IncorrectPassword { message }; } } } |