This commit is contained in:
Temirkhan Myrzamadi 2020-07-08 15:08:18 +06:00
commit 53625c9441
3 changed files with 16 additions and 14 deletions

View file

@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.3.0] - ??? ## [0.3.0] - ???
### Changed ### Changed
- Now methods which can send file to Telegram returns tokio::io::Result<T>. Early its could panic. ([issue 216](https://github.com/teloxide/teloxide/issues/216)) - Now methods which can send file to Telegram returns tokio::io::Result<T>. Early its could panic. ([issue 216](https://github.com/teloxide/teloxide/issues/216))
- Now provided description of unknown telegram error, by splitting ApiErrorKind at `ApiErrorKind` and `ApiErrorKindKnown` enums. ([issue 199](https://github.com/teloxide/teloxide/issues/199))
## [0.2.0] - 2020-02-25 ## [0.2.0] - 2020-02-25
### Added ### Added
- The functionality to parse commands only with a correct bot's name (breaks backwards compatibility) ([Issue 168](https://github.com/teloxide/teloxide/issues/168)). - The functionality to parse commands only with a correct bot's name (breaks backwards compatibility) ([Issue 168](https://github.com/teloxide/teloxide/issues/168)).

View file

@ -3,7 +3,6 @@ use reqwest::StatusCode;
use serde::Deserialize; use serde::Deserialize;
use thiserror::Error; use thiserror::Error;
//<editor-fold desc="download">
/// An error occurred after downloading a file. /// An error occurred after downloading a file.
#[derive(Debug, Error, From)] #[derive(Debug, Error, From)]
pub enum DownloadError { pub enum DownloadError {
@ -14,9 +13,6 @@ pub enum DownloadError {
Io(#[source] std::io::Error), Io(#[source] std::io::Error),
} }
//</editor-fold>
//<editor-fold desc="request">
/// An error occurred after making a request to Telegram. /// An error occurred after making a request to Telegram.
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum RequestError { pub enum RequestError {
@ -40,11 +36,19 @@ pub enum RequestError {
InvalidJson(#[source] serde_json::Error), InvalidJson(#[source] serde_json::Error),
} }
//</editor-fold> /// A kind of a API error returned from Telegram. If you receive Unknown value,
/// please [open the issue](https://github.com/teloxide/teloxide/issues/new) with description
/// A kind of an API error returned from Telegram. /// of error.
#[derive(Debug, Deserialize, PartialEq, Copy, Hash, Eq, Clone)] #[derive(Debug, Deserialize, PartialEq, Hash, Eq, Clone)]
#[serde(untagged)]
pub enum ApiErrorKind { pub enum ApiErrorKind {
Known(KnownApiErrorKind),
Unknown(String),
}
/// A kind of a known API error returned from Telegram.
#[derive(Debug, Deserialize, PartialEq, Copy, Hash, Eq, Clone)]
pub enum KnownApiErrorKind {
/// Occurs when the bot tries to send message to user who blocked the bot. /// Occurs when the bot tries to send message to user who blocked the bot.
#[serde(rename = "Forbidden: bot was blocked by the user")] #[serde(rename = "Forbidden: bot was blocked by the user")]
BotBlocked, BotBlocked,
@ -510,7 +514,4 @@ pub enum ApiErrorKind {
/// [`GetFile`]: crate::requests::GetFile /// [`GetFile`]: crate::requests::GetFile
#[serde(rename = "Bad Request: invalid file id")] #[serde(rename = "Bad Request: invalid file id")]
FileIdInvalid, FileIdInvalid,
#[serde(other)]
Other,
} }

View file

@ -62,11 +62,12 @@ impl<R> Into<ResponseResult<R>> for TelegramResponse<R> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::types::Update; use crate::{errors::KnownApiErrorKind, types::Update};
#[test] #[test]
fn terminated_by_other_get_updates() { fn terminated_by_other_get_updates() {
let expected = ApiErrorKind::TerminatedByOtherGetUpdates; let expected =
ApiErrorKind::Known(KnownApiErrorKind::TerminatedByOtherGetUpdates);
if let TelegramResponse::Err{ kind, .. } = serde_json::from_str::<TelegramResponse<Update>>(r#"{"ok":false,"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}"#).unwrap() { if let TelegramResponse::Err{ kind, .. } = serde_json::from_str::<TelegramResponse<Update>>(r#"{"ok":false,"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}"#).unwrap() {
assert_eq!(expected, kind); assert_eq!(expected, kind);
} }