mirror of
https://github.com/teloxide/teloxide.git
synced 2024-10-24 01:47:08 +02:00
splited ApiErrorKind at known and unknown
This commit is contained in:
parent
fe8146767e
commit
0393a8b53c
2 changed files with 14 additions and 3 deletions
|
@ -36,9 +36,19 @@ pub enum RequestError {
|
|||
InvalidJson(#[source] serde_json::Error),
|
||||
}
|
||||
|
||||
/// A kind of an API error returned from Telegram.
|
||||
#[derive(Debug, Deserialize, PartialEq, Copy, Hash, Eq, Clone)]
|
||||
/// A kind of an 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(ApiErrorKindKnown),
|
||||
Unknown(String)
|
||||
}
|
||||
|
||||
/// A kind of an known API error returned from Telegram.
|
||||
#[derive(Debug, Deserialize, PartialEq, Copy, Hash, Eq, Clone)]
|
||||
pub enum ApiErrorKindKnown {
|
||||
/// Occurs when the bot tries to send message to user who blocked the bot.
|
||||
#[serde(rename = "Forbidden: bot was blocked by the user")]
|
||||
BotBlocked,
|
||||
|
|
|
@ -63,10 +63,11 @@ impl<R> Into<ResponseResult<R>> for TelegramResponse<R> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::Update;
|
||||
use crate::errors::ApiErrorKindKnown;
|
||||
|
||||
#[test]
|
||||
fn terminated_by_other_get_updates() {
|
||||
let expected = ApiErrorKind::TerminatedByOtherGetUpdates;
|
||||
let expected = ApiErrorKind::Known(ApiErrorKindKnown::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