mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
commit
461d882bc1
4 changed files with 94 additions and 35 deletions
|
@ -21,11 +21,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- Refactor errors ([#134][pr134])
|
||||
- Rename `DownloadError::NetworkError` to `Network`
|
||||
- Rename `RequestError::ApiError` to `Api`
|
||||
- Remove `RequestError::Api::status_code` and rename `RequestError::Api::kind` to `0` (struct to tuple struct)
|
||||
- Rename `RequestError::NetworkError` to `Network`
|
||||
- Implement `Error` for `ApiError`
|
||||
- Use `url::Url` for urls, use `chrono::DateTime<Utc>` for dates in types ([#115][pr115])
|
||||
- Mark `ApiError` as `non_exhaustive` ([#125][pr125])
|
||||
|
||||
[pr115]: https://github.com/teloxide/teloxide-core/pull/115
|
||||
[pr125]: https://github.com/teloxide/teloxide-core/pull/125
|
||||
[pr134]: https://github.com/teloxide/teloxide-core/pull/134
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::io;
|
||||
|
||||
use derive_more::From;
|
||||
use reqwest::StatusCode;
|
||||
use serde::Deserialize;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -10,7 +9,7 @@ use thiserror::Error;
|
|||
pub enum DownloadError {
|
||||
/// A network error while downloading a file from Telegram.
|
||||
#[error("A network error: {0}")]
|
||||
NetworkError(#[source] reqwest::Error),
|
||||
Network(#[source] reqwest::Error),
|
||||
|
||||
/// An I/O error while writing a file to destination.
|
||||
#[error("An I/O error: {0}")]
|
||||
|
@ -21,14 +20,8 @@ pub enum DownloadError {
|
|||
#[derive(Debug, Error)]
|
||||
pub enum RequestError {
|
||||
/// A Telegram API error.
|
||||
#[error("A Telegram's error #{status_code}: {kind:?}")]
|
||||
ApiError {
|
||||
/// A kind of an API error.
|
||||
kind: ApiError,
|
||||
|
||||
/// An HTTP code returned by Telegram, not very useful in practice.
|
||||
status_code: StatusCode,
|
||||
},
|
||||
#[error("A Telegram's error: {0}")]
|
||||
Api(#[source] ApiError),
|
||||
|
||||
/// The group has been migrated to a supergroup with the specified
|
||||
/// identifier.
|
||||
|
@ -42,7 +35,7 @@ pub enum RequestError {
|
|||
|
||||
/// Network error while sending a request to Telegram.
|
||||
#[error("A network error: {0}")]
|
||||
NetworkError(#[source] reqwest::Error),
|
||||
Network(#[source] reqwest::Error),
|
||||
|
||||
/// Error while parsing a response from Telegram.
|
||||
///
|
||||
|
@ -59,12 +52,13 @@ pub enum RequestError {
|
|||
}
|
||||
|
||||
/// A kind of an API error.
|
||||
#[derive(Debug, Deserialize, PartialEq, Hash, Eq, Clone)]
|
||||
#[derive(Debug, Error, Deserialize, PartialEq, Hash, Eq, Clone)]
|
||||
#[serde(field_identifier)]
|
||||
#[non_exhaustive]
|
||||
pub enum ApiError {
|
||||
/// Occurs when the bot tries to send message to user who blocked the bot.
|
||||
#[serde(rename = "Forbidden: bot was blocked by the user")]
|
||||
#[error("Forbidden: bot was blocked by the user")]
|
||||
BotBlocked,
|
||||
|
||||
/// Occurs when bot tries to modify a message without modification content.
|
||||
|
@ -77,6 +71,10 @@ pub enum ApiError {
|
|||
rename = "Bad Request: message is not modified: specified new message content and reply \
|
||||
markup are exactly the same as a current content and reply markup of the message"
|
||||
)]
|
||||
#[error(
|
||||
"Bad Request: message is not modified: specified new message content and reply markup are \
|
||||
exactly the same as a current content and reply markup of the message"
|
||||
)]
|
||||
MessageNotModified,
|
||||
|
||||
/// Occurs when bot tries to forward or delete a message which was deleted.
|
||||
|
@ -88,6 +86,7 @@ pub enum ApiError {
|
|||
/// [`ForwardMessage`]: crate::payloads::ForwardMessage
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: MESSAGE_ID_INVALID")]
|
||||
#[error("Bad Request: MESSAGE_ID_INVALID")]
|
||||
MessageIdInvalid,
|
||||
|
||||
/// Occurs when bot tries to forward a message which does not exists.
|
||||
|
@ -97,6 +96,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`ForwardMessage`]: crate::payloads::ForwardMessage
|
||||
#[serde(rename = "Bad Request: message to forward not found")]
|
||||
#[error("Bad Request: message to forward not found")]
|
||||
MessageToForwardNotFound,
|
||||
|
||||
/// Occurs when bot tries to delete a message which does not exists.
|
||||
|
@ -106,6 +106,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: message to delete not found")]
|
||||
#[error("Bad Request: message to delete not found")]
|
||||
MessageToDeleteNotFound,
|
||||
|
||||
/// Occurs when bot tries to send a text message without text.
|
||||
|
@ -115,6 +116,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: message text is empty")]
|
||||
#[error("Bad Request: message text is empty")]
|
||||
MessageTextIsEmpty,
|
||||
|
||||
/// Occurs when bot tries to edit a message after long time.
|
||||
|
@ -124,6 +126,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
#[serde(rename = "Bad Request: message can't be edited")]
|
||||
#[error("Bad Request: message can't be edited")]
|
||||
MessageCantBeEdited,
|
||||
|
||||
/// Occurs when bot tries to delete a someone else's message in group where
|
||||
|
@ -134,6 +137,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: message can't be deleted")]
|
||||
#[error("Bad Request: message can't be deleted")]
|
||||
MessageCantBeDeleted,
|
||||
|
||||
/// Occurs when bot tries to edit a message which does not exists.
|
||||
|
@ -143,6 +147,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
#[serde(rename = "Bad Request: message to edit not found")]
|
||||
#[error("Bad Request: message to edit not found")]
|
||||
MessageToEditNotFound,
|
||||
|
||||
/// Occurs when bot tries to reply to a message which does not exists.
|
||||
|
@ -152,10 +157,12 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: reply message not found")]
|
||||
#[error("Bad Request: reply message not found")]
|
||||
MessageToReplyNotFound,
|
||||
|
||||
/// Occurs when bot tries to
|
||||
#[serde(rename = "Bad Request: message identifier is not specified")]
|
||||
#[error("Bad Request: message identifier is not specified")]
|
||||
MessageIdentifierNotSpecified,
|
||||
|
||||
/// Occurs when bot tries to send a message with text size greater then
|
||||
|
@ -166,6 +173,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: message is too long")]
|
||||
#[error("Bad Request: message is too long")]
|
||||
MessageIsTooLong,
|
||||
|
||||
/// Occurs when bot tries to edit a message with text size greater then
|
||||
|
@ -182,6 +190,7 @@ pub enum ApiError {
|
|||
/// [`EditMessageCaption`]: crate::payloads::EditMessageCaption
|
||||
/// [`EditMessageCaptionInline`]: crate::payloads::EditMessageCaptionInline
|
||||
#[serde(rename = "Bad Request: MESSAGE_TOO_LONG")]
|
||||
#[error("Bad Request: MESSAGE_TOO_LONG")]
|
||||
EditedMessageIsTooLong,
|
||||
|
||||
/// Occurs when bot tries to send media group with more than 10 items.
|
||||
|
@ -191,6 +200,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMediaGroup`]: crate::payloads::SendMediaGroup
|
||||
#[serde(rename = "Bad Request: Too much messages to send as an album")]
|
||||
#[error("Bad Request: Too much messages to send as an album")]
|
||||
ToMuchMessages,
|
||||
|
||||
/// Occurs when bot tries to answer an inline query with more than 50
|
||||
|
@ -212,6 +222,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll has already been closed")]
|
||||
#[error("Bad Request: poll has already been closed")]
|
||||
PollHasAlreadyClosed,
|
||||
|
||||
/// Occurs when bot tries to send poll with less than 2 options.
|
||||
|
@ -221,6 +232,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll must have at least 2 option")]
|
||||
#[error("Bad Request: poll must have at least 2 option")]
|
||||
PollMustHaveMoreOptions,
|
||||
|
||||
/// Occurs when bot tries to send poll with more than 10 options.
|
||||
|
@ -230,6 +242,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll can't have more than 10 options")]
|
||||
#[error("Bad Request: poll can't have more than 10 options")]
|
||||
PollCantHaveMoreOptions,
|
||||
|
||||
/// Occurs when bot tries to send poll with empty option (without text).
|
||||
|
@ -239,6 +252,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll options must be non-empty")]
|
||||
#[error("Bad Request: poll options must be non-empty")]
|
||||
PollOptionsMustBeNonEmpty,
|
||||
|
||||
/// Occurs when bot tries to send poll with empty question (without text).
|
||||
|
@ -248,6 +262,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll question must be non-empty")]
|
||||
#[error("Bad Request: poll question must be non-empty")]
|
||||
PollQuestionMustBeNonEmpty,
|
||||
|
||||
/// Occurs when bot tries to send poll with total size of options more than
|
||||
|
@ -258,6 +273,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll options length must not exceed 100")]
|
||||
#[error("Bad Request: poll options length must not exceed 100")]
|
||||
PollOptionsLengthTooLong,
|
||||
|
||||
/// Occurs when bot tries to send poll with question size more than 255
|
||||
|
@ -268,6 +284,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll question length must not exceed 255")]
|
||||
#[error("Bad Request: poll question length must not exceed 255")]
|
||||
PollQuestionLengthTooLong,
|
||||
|
||||
/// Occurs when bot tries to stop poll with message without poll.
|
||||
|
@ -277,6 +294,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`StopPoll`]: crate::payloads::StopPoll
|
||||
#[serde(rename = "Bad Request: message with poll to stop not found")]
|
||||
#[error("Bad Request: message with poll to stop not found")]
|
||||
MessageWithPollNotFound,
|
||||
|
||||
/// Occurs when bot tries to stop poll with message without poll.
|
||||
|
@ -286,6 +304,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`StopPoll`]: crate::payloads::StopPoll
|
||||
#[serde(rename = "Bad Request: message is not a poll")]
|
||||
#[error("Bad Request: message is not a poll")]
|
||||
MessageIsNotAPoll,
|
||||
|
||||
/// Occurs when bot tries to send a message to chat in which it is not a
|
||||
|
@ -296,6 +315,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: chat not found")]
|
||||
#[error("Bad Request: chat not found")]
|
||||
ChatNotFound,
|
||||
|
||||
/// Occurs when bot tries to send method with unknown user_id.
|
||||
|
@ -306,6 +326,7 @@ pub enum ApiError {
|
|||
/// [`getUserProfilePhotos`]:
|
||||
/// crate::payloads::GetUserProfilePhotos
|
||||
#[serde(rename = "Bad Request: user not found")]
|
||||
#[error("Bad Request: user not found")]
|
||||
UserNotFound,
|
||||
|
||||
/// Occurs when bot tries to send [`SetChatDescription`] with same text as
|
||||
|
@ -316,6 +337,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SetChatDescription`]: crate::payloads::SetChatDescription
|
||||
#[serde(rename = "Bad Request: chat description is not modified")]
|
||||
#[error("Bad Request: chat description is not modified")]
|
||||
ChatDescriptionIsNotModified,
|
||||
|
||||
/// Occurs when bot tries to answer to query after timeout expire.
|
||||
|
@ -328,6 +350,7 @@ pub enum ApiError {
|
|||
rename = "Bad Request: query is too old and response timeout expired or query id is \
|
||||
invalid"
|
||||
)]
|
||||
#[error("Bad Request: query is too old and response timeout expired or query id is invalid")]
|
||||
InvalidQueryId,
|
||||
|
||||
/// Occurs when bot tries to send InlineKeyboardMarkup with invalid button
|
||||
|
@ -338,6 +361,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: BUTTON_URL_INVALID")]
|
||||
#[error("Bad Request: BUTTON_URL_INVALID")]
|
||||
ButtonUrlInvalid,
|
||||
|
||||
/// Occurs when bot tries to send button with data size more than 64 bytes.
|
||||
|
@ -347,6 +371,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: BUTTON_DATA_INVALID")]
|
||||
#[error("Bad Request: BUTTON_DATA_INVALID")]
|
||||
ButtonDataInvalid,
|
||||
|
||||
/// Occurs when bot tries to send button with data size == 0.
|
||||
|
@ -359,6 +384,10 @@ pub enum ApiError {
|
|||
rename = "Bad Request: can't parse inline keyboard button: Text buttons are unallowed in \
|
||||
the inline keyboard"
|
||||
)]
|
||||
#[error(
|
||||
"Bad Request: can't parse inline keyboard button: Text buttons are unallowed in the \
|
||||
inline keyboard"
|
||||
)]
|
||||
TextButtonsAreUnallowed,
|
||||
|
||||
/// Occurs when bot tries to get file by wrong file id.
|
||||
|
@ -368,10 +397,12 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
#[serde(rename = "Bad Request: wrong file id")]
|
||||
#[error("Bad Request: wrong file id")]
|
||||
WrongFileId,
|
||||
|
||||
/// Occurs when bot tries to do some with group which was deactivated.
|
||||
#[serde(rename = "Bad Request: group is deactivated")]
|
||||
#[error("Bad Request: group is deactivated")]
|
||||
GroupDeactivated,
|
||||
|
||||
/// Occurs when bot tries to set chat photo from file ID
|
||||
|
@ -381,6 +412,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SetChatPhoto`]: crate::payloads::SetChatPhoto
|
||||
#[serde(rename = "Bad Request: Photo should be uploaded as an InputFile")]
|
||||
#[error("Bad Request: Photo should be uploaded as an InputFile")]
|
||||
PhotoAsInputFileRequired,
|
||||
|
||||
/// Occurs when bot tries to add sticker to stickerset by invalid name.
|
||||
|
@ -390,6 +422,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`AddStickerToSet`]: crate::payloads::AddStickerToSet
|
||||
#[serde(rename = "Bad Request: STICKERSET_INVALID")]
|
||||
#[error("Bad Request: STICKERSET_INVALID")]
|
||||
InvalidStickersSet,
|
||||
|
||||
/// Occurs when bot tries to create a sticker set with a name that is
|
||||
|
@ -400,6 +433,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`CreateNewStickerSet`]: crate::payloads::CreateNewStickerSet
|
||||
#[serde(rename = "Bad Request: sticker set name is already occupied")]
|
||||
#[error("Bad Request: sticker set name is already occupied")]
|
||||
StickerSetNameOccupied,
|
||||
|
||||
/// Occurs when bot tries to create a sticker set with user id of a bot.
|
||||
|
@ -409,6 +443,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`CreateNewStickerSet`]: crate::payloads::CreateNewStickerSet
|
||||
#[serde(rename = "Bad Request: USER_IS_BOT")]
|
||||
#[error("Bad Request: USER_IS_BOT")]
|
||||
StickerSetOwnerIsBot,
|
||||
|
||||
/// Occurs when bot tries to create a sticker set with invalid name.
|
||||
|
@ -425,6 +460,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`CreateNewStickerSet`]: crate::payloads::CreateNewStickerSet
|
||||
#[serde(rename = "Bad Request: invalid sticker set name is specified")]
|
||||
#[error("Bad Request: invalid sticker set name is specified")]
|
||||
InvalidStickerName,
|
||||
|
||||
/// Occurs when bot tries to pin a message without rights to pin in this
|
||||
|
@ -435,6 +471,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`PinChatMessage`]: crate::payloads::PinChatMessage
|
||||
#[serde(rename = "Bad Request: not enough rights to pin a message")]
|
||||
#[error("Bad Request: not enough rights to pin a message")]
|
||||
NotEnoughRightsToPinMessage,
|
||||
|
||||
/// Occurs when bot tries to pin or unpin a message without rights to pin
|
||||
|
@ -447,11 +484,13 @@ pub enum ApiError {
|
|||
/// [`PinChatMessage`]: crate::payloads::PinChatMessage
|
||||
/// [`UnpinChatMessage`]: crate::payloads::UnpinChatMessage
|
||||
#[serde(rename = "Bad Request: not enough rights to manage pinned messages in the chat")]
|
||||
#[error("Bad Request: not enough rights to manage pinned messages in the chat")]
|
||||
NotEnoughRightsToManagePins,
|
||||
|
||||
/// Occurs when bot tries to use method in group which is allowed only in a
|
||||
/// supergroup or channel.
|
||||
#[serde(rename = "Bad Request: method is available only for supergroups and channel")]
|
||||
#[error("Bad Request: method is available only for supergroups and channel")]
|
||||
MethodNotAvailableInPrivateChats,
|
||||
|
||||
/// Occurs when bot tries to demote chat creator.
|
||||
|
@ -461,6 +500,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`PromoteChatMember`]: crate::payloads::PromoteChatMember
|
||||
#[serde(rename = "Bad Request: can't demote chat creator")]
|
||||
#[error("Bad Request: can't demote chat creator")]
|
||||
CantDemoteChatCreator,
|
||||
|
||||
/// Occurs when bot tries to restrict self in group chats.
|
||||
|
@ -470,6 +510,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`RestrictChatMember`]: crate::payloads::RestrictChatMember
|
||||
#[serde(rename = "Bad Request: can't restrict self")]
|
||||
#[error("Bad Request: can't restrict self")]
|
||||
CantRestrictSelf,
|
||||
|
||||
/// Occurs when bot tries to restrict chat member without rights to
|
||||
|
@ -480,11 +521,13 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`RestrictChatMember`]: crate::payloads::RestrictChatMember
|
||||
#[serde(rename = "Bad Request: not enough rights to restrict/unrestrict chat member")]
|
||||
#[error("Bad Request: not enough rights to restrict/unrestrict chat member")]
|
||||
NotEnoughRightsToRestrict,
|
||||
|
||||
/// Occurs when bot tries to post a message in a channel without "Post
|
||||
/// Messages" admin right.
|
||||
#[serde(rename = "Bad Request: need administrator rights in the channel chat")]
|
||||
#[error("Bad Request: need administrator rights in the channel chat")]
|
||||
NotEnoughRightsToPostMessages,
|
||||
|
||||
/// Occurs when bot tries set webhook to protocol other than HTTPS.
|
||||
|
@ -494,6 +537,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: bad webhook: HTTPS url must be provided for webhook")]
|
||||
#[error("Bad Request: bad webhook: HTTPS url must be provided for webhook")]
|
||||
WebhookRequireHttps,
|
||||
|
||||
/// Occurs when bot tries to set webhook to port other than 80, 88, 443 or
|
||||
|
@ -507,6 +551,7 @@ pub enum ApiError {
|
|||
rename = "Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 or \
|
||||
8443"
|
||||
)]
|
||||
#[error("Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 or 8443")]
|
||||
BadWebhookPort,
|
||||
|
||||
/// Occurs when bot tries to set webhook to unknown host.
|
||||
|
@ -518,6 +563,7 @@ pub enum ApiError {
|
|||
#[serde(
|
||||
rename = "Bad Request: bad webhook: Failed to resolve host: Name or service not known"
|
||||
)]
|
||||
#[error("Bad Request: bad webhook: Failed to resolve host: Name or service not known")]
|
||||
UnknownHost,
|
||||
|
||||
/// Occurs when bot tries to set webhook to invalid URL.
|
||||
|
@ -527,6 +573,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: can't parse URL")]
|
||||
#[error("Bad Request: can't parse URL")]
|
||||
CantParseUrl,
|
||||
|
||||
/// Occurs when bot tries to send message with unfinished entities.
|
||||
|
@ -536,6 +583,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: can't parse entities")]
|
||||
#[error("Bad Request: can't parse entities")]
|
||||
CantParseEntities,
|
||||
|
||||
/// Occurs when bot tries to use getUpdates while webhook is active.
|
||||
|
@ -545,6 +593,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`GetUpdates`]: crate::payloads::GetUpdates
|
||||
#[serde(rename = "can't use getUpdates method while webhook is active")]
|
||||
#[error("can't use getUpdates method while webhook is active")]
|
||||
CantGetUpdates,
|
||||
|
||||
/// Occurs when bot tries to do some in group where bot was kicked.
|
||||
|
@ -554,6 +603,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot was kicked from a chat")]
|
||||
#[error("Unauthorized: bot was kicked from a chat")]
|
||||
BotKicked,
|
||||
|
||||
/// Occurs when bot tries to do something in a supergroup the bot was
|
||||
|
@ -564,6 +614,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Forbidden: bot was kicked from the supergroup chat")]
|
||||
#[error("Forbidden: bot was kicked from the supergroup chat")]
|
||||
BotKickedFromSupergroup,
|
||||
|
||||
/// Occurs when bot tries to send message to deactivated user.
|
||||
|
@ -573,6 +624,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: user is deactivated")]
|
||||
#[error("Unauthorized: user is deactivated")]
|
||||
UserDeactivated,
|
||||
|
||||
/// Occurs when you tries to initiate conversation with a user.
|
||||
|
@ -582,6 +634,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot can't initiate conversation with a user")]
|
||||
#[error("Unauthorized: bot can't initiate conversation with a user")]
|
||||
CantInitiateConversation,
|
||||
|
||||
/// Occurs when you tries to send message to bot.
|
||||
|
@ -591,6 +644,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot can't send messages to bots")]
|
||||
#[error("Unauthorized: bot can't send messages to bots")]
|
||||
CantTalkWithBots,
|
||||
|
||||
/// Occurs when bot tries to send button with invalid http url.
|
||||
|
@ -600,6 +654,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: wrong HTTP URL")]
|
||||
#[error("Bad Request: wrong HTTP URL")]
|
||||
WrongHttpUrl,
|
||||
|
||||
/// Occurs when bot tries GetUpdate before the timeout. Make sure that only
|
||||
|
@ -613,6 +668,10 @@ pub enum ApiError {
|
|||
rename = "Conflict: terminated by other getUpdates request; make sure that only one bot \
|
||||
instance is running"
|
||||
)]
|
||||
#[error(
|
||||
"Conflict: terminated by other getUpdates request; make sure that only one bot instance \
|
||||
is running"
|
||||
)]
|
||||
TerminatedByOtherGetUpdates,
|
||||
|
||||
/// Occurs when bot tries to get file by invalid file id.
|
||||
|
@ -622,6 +681,7 @@ pub enum ApiError {
|
|||
///
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
#[serde(rename = "Bad Request: invalid file id")]
|
||||
#[error("Bad Request: invalid file id")]
|
||||
FileIdInvalid,
|
||||
|
||||
/// Error which is not known to `teloxide`.
|
||||
|
@ -630,5 +690,6 @@ pub enum ApiError {
|
|||
/// description of the error.
|
||||
///
|
||||
/// [open an issue]: https://github.com/teloxide/teloxide/issues/new
|
||||
#[error("Unknown error: {0:?}")]
|
||||
Unknown(String),
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ where
|
|||
.multipart(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
.map_err(RequestError::Network)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ where
|
|||
.body(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
.map_err(RequestError::Network)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ where
|
|||
}
|
||||
|
||||
serde_json::from_str::<TelegramResponse<T>>(
|
||||
&response.text().await.map_err(RequestError::NetworkError)?,
|
||||
&response.text().await.map_err(RequestError::Network)?,
|
||||
)
|
||||
.map_err(RequestError::InvalidJson)?
|
||||
.into()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use reqwest::StatusCode;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
|
@ -14,6 +13,7 @@ pub(crate) enum TelegramResponse<R> {
|
|||
/// A dummy field. Used only for deserialization.
|
||||
#[allow(dead_code)]
|
||||
ok: True,
|
||||
|
||||
#[serde(rename = "result")]
|
||||
response: R,
|
||||
},
|
||||
|
@ -24,7 +24,10 @@ pub(crate) enum TelegramResponse<R> {
|
|||
|
||||
#[serde(rename = "description")]
|
||||
error: ApiError,
|
||||
error_code: u16,
|
||||
|
||||
// // This field is present in the json sent by telegram, but isn't currently used anywhere
|
||||
// // and as such - ignored
|
||||
// error_code: u16,
|
||||
#[serde(rename = "parameters")]
|
||||
response_parameters: Option<ResponseParameters>,
|
||||
},
|
||||
|
@ -35,25 +38,13 @@ impl<R> From<TelegramResponse<R>> for ResponseResult<R> {
|
|||
match this {
|
||||
TelegramResponse::Ok { response, .. } => Ok(response),
|
||||
TelegramResponse::Err {
|
||||
error,
|
||||
error_code,
|
||||
response_parameters,
|
||||
response_parameters: Some(params),
|
||||
..
|
||||
} => {
|
||||
if let Some(params) = response_parameters {
|
||||
match params {
|
||||
ResponseParameters::RetryAfter(i) => Err(RequestError::RetryAfter(i)),
|
||||
ResponseParameters::MigrateToChatId(to) => {
|
||||
Err(RequestError::MigrateToChatId(to))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(RequestError::ApiError {
|
||||
kind: error,
|
||||
status_code: StatusCode::from_u16(error_code).unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
} => Err(match params {
|
||||
ResponseParameters::RetryAfter(i) => RequestError::RetryAfter(i),
|
||||
ResponseParameters::MigrateToChatId(to) => RequestError::MigrateToChatId(to),
|
||||
}),
|
||||
TelegramResponse::Err { error, .. } => Err(RequestError::Api(error)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue