From 16a16912122628e51231464c1546961d7d36b918 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 7 May 2024 17:38:26 +0200 Subject: [PATCH] Ignore teloxide::ApiError::MessageToForwardNotFound --- .gitignore | 2 ++ src/core/file_utils.rs | 10 ++++++++-- src/core/views.rs | 9 +++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4a25947..689a82d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ __pycache__ venv +.DS_Store + # Added by cargo /target diff --git a/src/core/file_utils.rs b/src/core/file_utils.rs index 5922297..cbdf9cb 100644 --- a/src/core/file_utils.rs +++ b/src/core/file_utils.rs @@ -69,7 +69,7 @@ pub async fn upload_file( } } -pub async fn download_file(chat_id: i64, message_id: i32) -> Result> { +pub async fn download_file(chat_id: i64, message_id: i32) -> Result, Box> { let bot = ROUND_ROBIN_BOT.get_bot(); let forwarded_message = match bot @@ -82,6 +82,12 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result v, Err(err) => { + if let teloxide::RequestError::Api(ref err) = err { + if let teloxide::ApiError::MessageToForwardNotFound = err { + return Ok(None); + } + } + log::error!("Error: {}", err); return Err(Box::new(err)); } @@ -99,5 +105,5 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result) -> impl IntoResponse { async fn download(Path((chat_id, message_id)): Path<(i64, i32)>) -> impl IntoResponse { let file = match download_file(chat_id, message_id).await { - Ok(v) => v, + Ok(v) => { + match v { + Some(v) => v, + None => return StatusCode::BAD_REQUEST.into_response(), + } + }, Err(err) => { log::error!("{}", err); return StatusCode::BAD_REQUEST.into_response() } - } ; + }; let reader = ReaderStream::new(file);