pub enum TelegramError {
InvalidToken(String),
MessageTooLarge {
bytes: usize,
max: usize,
},
Http(Error),
Api {
error_code: i32,
description: String,
},
RateLimited {
retry_after: Duration,
},
Serialization(Error),
Internal(String),
}Expand description
Every way a Telegram send can fail.
Note that TelegramError::Http always holds a reqwest::Error which has
had its URL stripped via reqwest::Error::without_url. The bot token is a
path segment of every request URL, and reqwest’s own Debug includes the
URL, so an un-stripped error would leak the credential into any log line.
Variants§
InvalidToken(String)
The bot token was empty or malformed.
MessageTooLarge
The message was too large to even attempt to send.
This is a guard against an upstream bug producing a multi-megabyte string; it is checked before chunking, so it is never the result of merely exceeding Telegram’s per-message limit.
Fields
Http(Error)
The HTTP request itself failed (connection refused, TLS failure, timeout).
Api
Telegram accepted the request but rejected its contents.
Fields
RateLimited
Telegram returned 429 along with how long to wait.
This is distinct from a plain TelegramError::Api 429 because it
carries an actionable delay: Telegram is telling us precisely when the
request may be repeated.
Serialization(Error)
The response body could not be deserialized.
Internal(String)
An invariant inside this library was violated.
Implementations§
Source§impl TelegramError
impl TelegramError
Sourcepub const fn is_permanent(&self) -> bool
pub const fn is_permanent(&self) -> bool
Whether this error is permanent, meaning a retry can never succeed.
A permanent error almost always means the notifier is misconfigured rather than that this particular message was bad: a wrong token, a chat the bot was removed from, a chat id that does not exist. Every subsequent send will fail the same way.
Sourcepub fn is_misconfiguration(&self) -> bool
pub fn is_misconfiguration(&self) -> bool
Whether this error indicates the notifier as a whole is misconfigured.
These deserve a louder log than an ordinary send failure, because they mean every future send is also doomed:
401— the bot token is wrong.403— the bot was blocked, or removed from the chat.400with a chat-related description — the chat id is wrong.
Trait Implementations§
Source§impl Debug for TelegramError
impl Debug for TelegramError
Source§impl Display for TelegramError
impl Display for TelegramError
Source§impl Error for TelegramError
impl Error for TelegramError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for TelegramError
impl From<Error> for TelegramError
Auto Trait Implementations§
impl !RefUnwindSafe for TelegramError
impl !UnwindSafe for TelegramError
impl Freeze for TelegramError
impl Send for TelegramError
impl Sync for TelegramError
impl Unpin for TelegramError
impl UnsafeUnpin for TelegramError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.