pub struct RpcError {
pub code: i32,
pub name: String,
pub value: Option<u32>,
}Expand description
An error returned by Telegram’s servers in response to an RPC call.
Numeric values are stripped from the name and placed in RpcError::value.
§Example
FLOOD_WAIT_30 → RpcError { code: 420, name: "FLOOD_WAIT", value: Some(30) }
Fields§
§code: i32HTTP-like status code.
name: StringError name in SCREAMING_SNAKE_CASE with digits removed.
value: Option<u32>Numeric suffix extracted from the name, if any.
Implementations§
Source§impl RpcError
impl RpcError
Sourcepub fn from_telegram(code: i32, message: &str) -> Self
pub fn from_telegram(code: i32, message: &str) -> Self
Parse a raw Telegram error message like "FLOOD_WAIT_30" into an RpcError.
Sourcepub fn is(&self, pattern: &str) -> bool
pub fn is(&self, pattern: &str) -> bool
Match on the error name, with optional wildcard prefix/suffix '*'.
§Examples
err.is("FLOOD_WAIT"): exact matcherr.is("PHONE_CODE_*"): starts-with matcherr.is("*_INVALID"): ends-with match
Sourcepub fn flood_wait_seconds(&self) -> Option<u64>
pub fn flood_wait_seconds(&self) -> Option<u64>
Returns the flood-wait duration in seconds, if this is a FLOOD_WAIT error.
Source§impl RpcError
Extension methods on crate::errors::RpcError for routing decisions.
impl RpcError
Extension methods on crate::errors::RpcError for routing decisions.
Sourcepub fn migrate_dc_id(&self) -> Option<i32>
pub fn migrate_dc_id(&self) -> Option<i32>
If this is a DC-migration redirect (code 303), returns the target DC id.
Telegram sends these for:
PHONE_MIGRATE_X: user’s home DC during authNETWORK_MIGRATE_X: general redirectFILE_MIGRATE_X: file download/upload DCUSER_MIGRATE_X: account migration
All have code == 303 and a numeric suffix that is the DC id.
Trait Implementations§
Source§impl Error for RpcError
impl Error for RpcError
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()
impl StructuralPartialEq for RpcError
Auto Trait Implementations§
impl Freeze for RpcError
impl RefUnwindSafe for RpcError
impl Send for RpcError
impl Sync for RpcError
impl Unpin for RpcError
impl UnsafeUnpin for RpcError
impl UnwindSafe for RpcError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more