errors.rs (1338B)
1 use serde::{Deserialize, Serialize}; 2 use std::fmt; 3 use thiserror::Error; 4 5 #[derive(Debug, Clone, Serialize, Deserialize)] 6 pub enum Field { 7 Homeserver, 8 MXID, 9 Password, 10 } 11 12 impl fmt::Display for Field { 13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 14 match *self { 15 Field::Homeserver => write!(f, "Homeserver Field"), 16 Field::MXID => write!(f, "MXID Field"), 17 Field::Password => write!(f, "Password Field"), 18 } 19 } 20 } 21 22 // TODO figure out a way to translate this 23 #[derive(Error, Debug, Clone, Serialize, Deserialize)] 24 pub enum MatrixError { 25 #[error("No Matrix Client is available yet")] 26 MissingClient, 27 #[error("Missing required Data in {0}")] 28 MissingFields(Field), 29 30 /// An error occurred in the Matrix client library. 31 /// This can't use transparent as we need Clone 32 #[error("A Timeout happened on Login")] 33 LoginTimeout, 34 35 /// An error occurred in the Matrix client library. 36 /// This can't use transparent as we need Clone 37 #[error("An error occurred in the Matrix client library: `{0}`")] 38 SDKError(String), 39 40 /// An error occurred in the URL parse library. 41 /// This can't use transparent as we need Serialize, Deserialize 42 #[error("An error occurred in the URL parse library: `{0}`")] 43 UrlParseError(String), 44 }