Ignore teloxide::ApiError::MessageToForwardNotFound

This commit is contained in:
2024-05-07 17:38:26 +02:00
parent b705b0cb30
commit 16a1691212
3 changed files with 17 additions and 4 deletions

2
.gitignore vendored
View File

@@ -11,6 +11,8 @@ __pycache__
venv venv
.DS_Store
# Added by cargo # Added by cargo
/target /target

View File

@@ -69,7 +69,7 @@ pub async fn upload_file(
} }
} }
pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dyn Error>> { pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>, Box<dyn Error>> {
let bot = ROUND_ROBIN_BOT.get_bot(); let bot = ROUND_ROBIN_BOT.get_bot();
let forwarded_message = match bot let forwarded_message = match bot
@@ -82,6 +82,12 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dy
{ {
Ok(v) => v, Ok(v) => v,
Err(err) => { Err(err) => {
if let teloxide::RequestError::Api(ref err) = err {
if let teloxide::ApiError::MessageToForwardNotFound = err {
return Ok(None);
}
}
log::error!("Error: {}", err); log::error!("Error: {}", err);
return Err(Box::new(err)); return Err(Box::new(err));
} }
@@ -99,5 +105,5 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dy
} }
}; };
Ok(File::open(path).await?) Ok(Some(File::open(path).await?))
} }

View File

@@ -91,7 +91,12 @@ async fn upload(data: TypedMultipart<UploadFileRequest>) -> impl IntoResponse {
async fn download(Path((chat_id, message_id)): Path<(i64, i32)>) -> 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 { 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) => { Err(err) => {
log::error!("{}", err); log::error!("{}", err);
return StatusCode::BAD_REQUEST.into_response() return StatusCode::BAD_REQUEST.into_response()