From 8b95dc20922d90ece9768c6287436cb81db33394 Mon Sep 17 00:00:00 2001 From: ByteDream Date: Thu, 13 Apr 2023 20:58:29 +0200 Subject: [PATCH] Add rate limit notice if detected --- crunchy-cli-core/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crunchy-cli-core/src/lib.rs b/crunchy-cli-core/src/lib.rs index 77df2c8..30b9157 100644 --- a/crunchy-cli-core/src/lib.rs +++ b/crunchy-cli-core/src/lib.rs @@ -16,6 +16,7 @@ mod login; mod utils; pub use archive::Archive; +use crunchyroll_rs::error::CrunchyrollError; pub use download::Download; pub use login::Login; @@ -200,6 +201,20 @@ async fn execute_executor(mut executor: impl Execute, ctx: Context) { if let Err(err) = executor.execute(ctx).await { error!("a unexpected error occurred: {}", err); + + if let Some(crunchy_error) = err.downcast_ref::() { + let message = match crunchy_error { + CrunchyrollError::Internal(i) => &i.message, + CrunchyrollError::Request(r) => &r.message, + CrunchyrollError::Decode(d) => &d.message, + CrunchyrollError::Authentication(a) => &a.message, + CrunchyrollError::Input(i) => &i.message, + }; + if message.contains("content.get_video_streams_v2.cms_service_error") { + error!("You've probably hit a rate limit. Try again later, generally after 10-20 minutes the rate limit is over and you can continue to use the cli") + } + } + std::process::exit(1) } }