mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Merge branch 'master' of https://github.com/teloxide/teloxide
This commit is contained in:
commit
53625c9441
3 changed files with 16 additions and 14 deletions
|
@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [0.3.0] - ???
|
||||
### 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 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
|
||||
### 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)).
|
||||
|
|
|
@ -3,7 +3,6 @@ use reqwest::StatusCode;
|
|||
use serde::Deserialize;
|
||||
use thiserror::Error;
|
||||
|
||||
//<editor-fold desc="download">
|
||||
/// An error occurred after downloading a file.
|
||||
#[derive(Debug, Error, From)]
|
||||
pub enum DownloadError {
|
||||
|
@ -14,9 +13,6 @@ pub enum DownloadError {
|
|||
Io(#[source] std::io::Error),
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold desc="request">
|
||||
/// An error occurred after making a request to Telegram.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RequestError {
|
||||
|
@ -40,11 +36,19 @@ pub enum RequestError {
|
|||
InvalidJson(#[source] serde_json::Error),
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
/// A kind of an API error returned from Telegram.
|
||||
#[derive(Debug, Deserialize, PartialEq, Copy, Hash, Eq, Clone)]
|
||||
/// 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
|
||||
/// of error.
|
||||
#[derive(Debug, Deserialize, PartialEq, Hash, Eq, Clone)]
|
||||
#[serde(untagged)]
|
||||
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.
|
||||
#[serde(rename = "Forbidden: bot was blocked by the user")]
|
||||
BotBlocked,
|
||||
|
@ -510,7 +514,4 @@ pub enum ApiErrorKind {
|
|||
/// [`GetFile`]: crate::requests::GetFile
|
||||
#[serde(rename = "Bad Request: invalid file id")]
|
||||
FileIdInvalid,
|
||||
|
||||
#[serde(other)]
|
||||
Other,
|
||||
}
|
||||
|
|
|
@ -62,11 +62,12 @@ impl<R> Into<ResponseResult<R>> for TelegramResponse<R> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::Update;
|
||||
use crate::{errors::KnownApiErrorKind, types::Update};
|
||||
|
||||
#[test]
|
||||
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() {
|
||||
assert_eq!(expected, kind);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue