From 8fff807ae68b61931aa8b1c899b8c8bba4df0784 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 20 Apr 2024 00:22:46 +0200 Subject: [PATCH] Add message if stored login is expired --- crunchy-cli-core/src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crunchy-cli-core/src/lib.rs b/crunchy-cli-core/src/lib.rs index 1ec5281..1c180e8 100644 --- a/crunchy-cli-core/src/lib.rs +++ b/crunchy-cli-core/src/lib.rs @@ -337,9 +337,19 @@ async fn crunchyroll_session( if let Some((token_type, token)) = session.split_once(':') { match token_type { "refresh_token" => { - return Ok(builder.login_with_refresh_token(token).await?) + return match builder.login_with_refresh_token(token).await { + Ok(crunchy) => Ok(crunchy), + Err(e) => { + if let Error::Request { message, .. } = &e { + if message.starts_with("invalid_grant") { + bail!("The stored login is expired, please login again") + } + } + Err(e.into()) + } + } } - "etp_rt" => bail!("The stored login method (etp-rt) isn't supported anymore. Please use your credentials to login"), + "etp_rt" => bail!("The stored login method (etp-rt) isn't supported anymore. Please login again using your credentials"), _ => (), } }