2020-07-01 07:30:38 +00:00
|
|
|
use network::{NetworkError, ParticipantError, StreamError};
|
2019-03-03 22:02:38 +00:00
|
|
|
|
2020-07-21 09:59:00 +00:00
|
|
|
use std::fmt::{self, Display};
|
|
|
|
|
2019-03-03 22:02:38 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2020-07-01 07:30:38 +00:00
|
|
|
NetworkErr(NetworkError),
|
|
|
|
ParticipantErr(ParticipantError),
|
|
|
|
StreamErr(StreamError),
|
2020-09-17 23:02:14 +00:00
|
|
|
DatabaseErr(diesel::result::Error),
|
2019-03-03 22:02:38 +00:00
|
|
|
Other(String),
|
|
|
|
}
|
|
|
|
|
2020-07-01 07:30:38 +00:00
|
|
|
impl From<NetworkError> for Error {
|
|
|
|
fn from(err: NetworkError) -> Self { Error::NetworkErr(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParticipantError> for Error {
|
|
|
|
fn from(err: ParticipantError) -> Self { Error::ParticipantErr(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<StreamError> for Error {
|
|
|
|
fn from(err: StreamError) -> Self { Error::StreamErr(err) }
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
2020-07-21 09:59:00 +00:00
|
|
|
|
2020-09-17 23:02:14 +00:00
|
|
|
impl From<diesel::result::Error> for Error {
|
|
|
|
fn from(err: diesel::result::Error) -> Self { Error::DatabaseErr(err) }
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:59:00 +00:00
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::NetworkErr(err) => write!(f, "Network Error: {}", err),
|
|
|
|
Self::ParticipantErr(err) => write!(f, "Participant Error: {}", err),
|
|
|
|
Self::StreamErr(err) => write!(f, "Stream Error: {}", err),
|
2020-09-17 23:02:14 +00:00
|
|
|
Self::DatabaseErr(err) => write!(f, "Database Error: {}", err),
|
2020-07-21 09:59:00 +00:00
|
|
|
Self::Other(err) => write!(f, "Error: {}", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|