diff --git a/crates/teloxide-core/src/adaptors/throttle/request.rs b/crates/teloxide-core/src/adaptors/throttle/request.rs index 46235fce..47e7d451 100644 --- a/crates/teloxide-core/src/adaptors/throttle/request.rs +++ b/crates/teloxide-core/src/adaptors/throttle/request.rs @@ -202,7 +202,7 @@ where let retry_after = res.as_ref().err().and_then(<_>::retry_after); if let Some(retry_after) = retry_after { - let after = retry_after; + let after = retry_after.duration(); let until = Instant::now() + after; // If we'll retry, we check that worker hasn't died at the start of the loop diff --git a/crates/teloxide-core/src/adaptors/throttle/worker.rs b/crates/teloxide-core/src/adaptors/throttle/worker.rs index 4712b22f..7aa42692 100644 --- a/crates/teloxide-core/src/adaptors/throttle/worker.rs +++ b/crates/teloxide-core/src/adaptors/throttle/worker.rs @@ -316,7 +316,7 @@ async fn freeze( match chat.slow_mode_delay() { Some(delay) => { let now = Instant::now(); - let new_delay = Duration::from_secs(delay.into()); + let new_delay = delay.duration(); slow_mode.insert(hash, (new_delay, now)); } None => { diff --git a/crates/teloxide-core/src/errors.rs b/crates/teloxide-core/src/errors.rs index 69fecdeb..95c1e765 100644 --- a/crates/teloxide-core/src/errors.rs +++ b/crates/teloxide-core/src/errors.rs @@ -1,10 +1,10 @@ //! Possible error types. -use std::{io, time::Duration}; +use std::io; use thiserror::Error; -use crate::types::ResponseParameters; +use crate::types::{ChatId, ResponseParameters, Seconds}; /// An error caused by sending a request to Telegram. #[derive(Debug, Error)] @@ -16,13 +16,12 @@ pub enum RequestError { /// The group has been migrated to a supergroup with the specified /// identifier. #[error("The group has been migrated to a supergroup with ID #{0}")] - // FIXME: change to `ChatId` :| - MigrateToChatId(i64), + MigrateToChatId(ChatId), /// In case of exceeding flood control, the number of seconds left to wait /// before the request can be repeated. - #[error("Retry after {0:?}")] - RetryAfter(Duration), + #[error("Retry after {0}")] + RetryAfter(Seconds), /// Network error while sending a request to Telegram. #[error("A network error: {0}")] @@ -64,14 +63,14 @@ pub enum DownloadError { pub trait AsResponseParameters { fn response_parameters(&self) -> Option; - fn retry_after(&self) -> Option { + fn retry_after(&self) -> Option { self.response_parameters().and_then(|rp| match rp { ResponseParameters::RetryAfter(n) => Some(n), _ => None, }) } - fn migrate_to_chat_id(&self) -> Option { + fn migrate_to_chat_id(&self) -> Option { self.response_parameters().and_then(|rp| match rp { ResponseParameters::MigrateToChatId(id) => Some(id), _ => None, diff --git a/crates/teloxide-core/src/net/request.rs b/crates/teloxide-core/src/net/request.rs index b990e588..dc9c5a88 100644 --- a/crates/teloxide-core/src/net/request.rs +++ b/crates/teloxide-core/src/net/request.rs @@ -162,7 +162,7 @@ where #[cfg(test)] mod tests { - use std::time::Duration; + use crate::types::{ChatId, Seconds}; use cool_asserts::assert_matches; @@ -194,7 +194,7 @@ mod tests { let json = r#"{"ok":false,"description":"this string is ignored","parameters":{"migrate_to_chat_id":123456}}"#.to_owned(); let res = deserialize_response::(json); - assert_matches!(res, Err(RequestError::MigrateToChatId(123456))); + assert_matches!(res, Err(RequestError::MigrateToChatId(ChatId(123456)))); } #[test] @@ -202,7 +202,7 @@ mod tests { let json = r#"{"ok":false,"description":"this string is ignored","parameters":{"retry_after":123456}}"#.to_owned(); let res = deserialize_response::(json); - assert_matches!(res, Err(RequestError::RetryAfter(duration)) if duration == Duration::from_secs(123456)); + assert_matches!(res, Err(RequestError::RetryAfter(duration)) if duration == Seconds::from_seconds(123456)); } #[test]