feat: add deprecated
LibraryError
This commit is contained in:
parent
a1089b5af7
commit
daa2aedf0c
2 changed files with 30 additions and 48 deletions
|
@ -37,6 +37,8 @@ pub enum LibraryError {
|
||||||
DecodeError(String),
|
DecodeError(String),
|
||||||
#[error("upstream api was changed. not continuing")]
|
#[error("upstream api was changed. not continuing")]
|
||||||
APIChange,
|
APIChange,
|
||||||
|
#[error("upstream api was changed. this method is deprecated")]
|
||||||
|
Deprecated,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type LibraryResult<T> = Result<T, LibraryError>;
|
pub type LibraryResult<T> = Result<T, LibraryError>;
|
||||||
|
|
|
@ -323,58 +323,32 @@ impl Login {
|
||||||
libpaket::LibraryError::Unauthorized => {
|
libpaket::LibraryError::Unauthorized => {
|
||||||
sender.input(LoginInput::NeedsLogin);
|
sender.input(LoginInput::NeedsLogin);
|
||||||
}
|
}
|
||||||
|
libpaket::LibraryError::Deprecated => {
|
||||||
|
sender.output(LoginOutput::Error(res)).unwrap();
|
||||||
|
sender.input(LoginInput::BreakWorld);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_library_error_to_response_type(err: &LibraryError) -> ResponseType {
|
macro_rules! received {
|
||||||
match err {
|
($func_name:ident, $args:tt, $calling:ident, $calling_args:tt) => {
|
||||||
LibraryError::NetworkFetch => ResponseType::Retry,
|
async fn $func_name$args -> LoginCommand {
|
||||||
LibraryError::Unauthorized => ResponseType::Okay,
|
|
||||||
LibraryError::InvalidArgument(_) => ResponseType::Okay,
|
|
||||||
LibraryError::DecodeError(_) => ResponseType::Okay,
|
|
||||||
LibraryError::APIChange => ResponseType::Okay,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn received_auth_code(auth_code: String, code_verifier: CodeVerfier) -> LoginCommand {
|
|
||||||
let client = OpenIdClient::new();
|
let client = OpenIdClient::new();
|
||||||
let mut err = LibraryError::NetworkFetch;
|
let mut err = LibraryError::NetworkFetch;
|
||||||
for _ in 0..6 {
|
for _ in 0..6 {
|
||||||
let result: Result<TokenResponse, LibraryError> = client
|
let result: Result<TokenResponse, LibraryError> = client
|
||||||
.token_authorization(auth_code.clone(), &code_verifier)
|
.$calling$calling_args
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(result) = result {
|
|
||||||
return LoginCommand::Token(Ok(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = result.unwrap_err();
|
|
||||||
let response_type = convert_library_error_to_response_type(&err);
|
|
||||||
if response_type == ResponseType::Retry {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return LoginCommand::Token(Err(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LoginCommand::Token(Err(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn use_refresh_token(refresh_token: RefreshToken) -> LoginCommand {
|
|
||||||
let client = OpenIdClient::new();
|
|
||||||
let mut err = LibraryError::NetworkFetch;
|
|
||||||
for _ in 0..6 {
|
|
||||||
let result: Result<TokenResponse, LibraryError> =
|
|
||||||
client.token_refresh(&refresh_token).await;
|
|
||||||
|
|
||||||
err = match result {
|
err = match result {
|
||||||
Ok(result) => return LoginCommand::Token(Ok(result)),
|
Ok(result) => return LoginCommand::Token(Ok(result)),
|
||||||
Err(err) => err,
|
Err(err) => err,
|
||||||
};
|
};
|
||||||
let response_type = convert_library_error_to_response_type(&err);
|
|
||||||
if response_type == ResponseType::Retry {
|
if err == LibraryError::NetworkFetch {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return LoginCommand::Token(Err(err));
|
return LoginCommand::Token(Err(err));
|
||||||
|
@ -382,3 +356,9 @@ async fn use_refresh_token(refresh_token: RefreshToken) -> LoginCommand {
|
||||||
}
|
}
|
||||||
LoginCommand::Token(Err(err))
|
LoginCommand::Token(Err(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
received!(received_auth_code, (auth_code: String, code_verifier: CodeVerfier), token_authorization, (auth_code.clone(), &code_verifier));
|
||||||
|
received!(use_refresh_token, (refresh_token: RefreshToken), token_refresh, (&refresh_token));
|
||||||
|
|
Loading…
Reference in a new issue