Added InvalidPeerInput Validation error case for Display trait + removed multisession errors from SocialVoidError

This commit is contained in:
Mahesh Bansod 2021-11-05 16:42:57 +05:30
parent 59847a5032
commit c95c71c1bd
3 changed files with 9 additions and 16 deletions

View File

@ -1,5 +1,6 @@
use socialvoid::{ClientError, SocialvoidError};
use socialvoid_rawclient::ErrorKind;
use socialvoid_rawclient::ValidationError;
pub struct MyFriendlyError(SocialvoidError);
@ -39,24 +40,21 @@ socialvoid-cli logout",
err
)
}
ErrorKind::Validation(ValidationError::InvalidPeerInput) => {
write!(
f,
"{}\nDid you forget to prefix with `@` incase of a username?",
err.description
)
}
_ => {
write!(f, "{:#?}", self.0)
}
},
SocialvoidError::Client(err) => match err {
ClientError::NoSessionsExist => {
write!(f, "Seems you need to create a session.")
}
ClientError::SerdeJson(err) => {
write!(f, "Error while parsing JSON.\n{:?}", err)
}
ClientError::SessionIndexOutOfBounds { session_count } => {
write!(
f,
"SessionIndexOutOfBounds. Number of sessions is {}",
session_count
)
}
},
}
}

View File

@ -7,12 +7,6 @@ pub enum SocialvoidError {
/// Errors generated by the client
#[derive(Debug)]
pub enum ClientError {
/// Thrown when `current_session` is `None`, typically means there aren't any
/// sessions and you should create one.
NoSessionsExist,
/// Thrown when tried to access a session via index and it's out of bounds.
/// Also, returns the number of sessions that we have
SessionIndexOutOfBounds { session_count: usize },
/// Errors thrown by serde json
SerdeJson(serde_json::Error),
}

View File

@ -14,6 +14,7 @@ use tokio_util::codec::{BytesCodec, FramedRead};
pub use error::errors::AuthenticationError;
pub use error::errors::ClientError;
pub use error::errors::ValidationError;
pub use error::Error;
pub use error::ErrorKind;