mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-02 00:42:10 +00:00
fix: honor media retry-after delay
This commit is contained in:
@@ -170,11 +170,14 @@ async fn download_to_temp(
|
|||||||
/// retry could only ask the same URL again.
|
/// retry could only ask the same URL again.
|
||||||
fn classify_download_error(err: FetchError) -> FallbackError {
|
fn classify_download_error(err: FetchError) -> FallbackError {
|
||||||
match err {
|
match err {
|
||||||
FetchError::Http(_) | FetchError::Transient(_) | FetchError::RateLimited { .. } => {
|
FetchError::RateLimited {
|
||||||
FallbackError::Retryable {
|
retry_after_secs, ..
|
||||||
|
} => FallbackError::Retryable {
|
||||||
|
delay_seconds: retry_after_secs as f64,
|
||||||
|
},
|
||||||
|
FetchError::Http(_) | FetchError::Transient(_) => FallbackError::Retryable {
|
||||||
delay_seconds: retry_delay_seconds(0),
|
delay_seconds: retry_delay_seconds(0),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
FetchError::TooLarge => FallbackError::MediaTooLarge,
|
FetchError::TooLarge => FallbackError::MediaTooLarge,
|
||||||
e => FallbackError::Permanent {
|
e => FallbackError::Permanent {
|
||||||
message: format!("download failed: {e}"),
|
message: format!("download failed: {e}"),
|
||||||
@@ -427,6 +430,17 @@ mod download_class_tests {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rate_limited_media_keeps_the_server_delay() {
|
||||||
|
match classify_download_error(FetchError::RateLimited {
|
||||||
|
site: "media",
|
||||||
|
retry_after_secs: 60,
|
||||||
|
}) {
|
||||||
|
FallbackError::Retryable { delay_seconds } => assert_eq!(delay_seconds, 60.0),
|
||||||
|
_ => panic!("expected retryable rate limit"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn a_file_id_item_is_refused_before_any_download() {
|
async fn a_file_id_item_is_refused_before_any_download() {
|
||||||
let item = MediaItemPayload::Photo {
|
let item = MediaItemPayload::Photo {
|
||||||
|
|||||||
Reference in New Issue
Block a user