pub struct RpcError {
pub code: i32,
pub name: String,
pub value: Option<u32>,
pub caused_by: Option<u32>,
}Expand description
The error type reported by the server when a request is misused.
These are returned when Telegram respond to an RPC with tl::types::RpcError.
Fields§
§code: i32A numerical value similar to HTTP response status codes.
name: StringThe ASCII error name, normally in screaming snake case.
Digit words are removed from the name and put in the RpcError::value instead.
use grammers_mtsender::RpcError;
let rpc_error = RpcError::from(grammers_tl_types::types::RpcError {
error_code: 500, error_message: "INTERDC_2_CALL_ERROR".into() });
assert_eq!(rpc_error.name, "INTERDC_CALL_ERROR");
assert_eq!(rpc_error.value, Some(2));value: Option<u32>If the error contained an additional integer value, it will be present here and removed from the RpcError::name.
use grammers_mtsender::RpcError;
let rpc_error = RpcError::from(grammers_tl_types::types::RpcError {
error_code: 420, error_message: "FLOOD_WAIT_31".into() });
assert_eq!(rpc_error.name, "FLOOD_WAIT");
assert_eq!(rpc_error.value, Some(31));caused_by: Option<u32>The constructor identifier of the request that triggered this error. Won’t be present if the error was artificially constructed.
Implementations§
Source§impl RpcError
impl RpcError
Sourcepub fn is(&self, rpc_error: &str) -> bool
pub fn is(&self, rpc_error: &str) -> bool
Matches on the name of the RPC error (case-sensitive).
Useful in match arm guards. A single trailing or leading asterisk ('*') is allowed,
and will instead check if the error name starts (or ends with) the input parameter.
§Examples
match request_result {
Err(rpc_err) if rpc_err.is("SESSION_PASSWORD_NEEDED") => panic!(),
Err(rpc_err) if rpc_err.is("PHONE_CODE_*") => {},
_ => panic!()
}Sourcepub fn with_caused_by(self, constructor_id: u32) -> Self
pub fn with_caused_by(self, constructor_id: u32) -> Self
Attaches the tl::Identifiable::CONSTRUCTOR_ID of the
request that caused this error to the error information.