2020-04-13 22:03:06 +02:00
|
|
|
use super::super::{RedisConnErr, RedisParseErr};
|
2020-04-22 20:38:22 +02:00
|
|
|
use super::{Event, EventErr};
|
2020-04-13 22:03:06 +02:00
|
|
|
use crate::request::{Timeline, TimelineErr};
|
2020-04-01 21:35:24 +02:00
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
#[derive(Debug)]
|
2020-04-22 20:38:22 +02:00
|
|
|
pub enum Error {
|
2020-04-09 00:39:52 +02:00
|
|
|
InvalidId,
|
2020-04-24 01:28:26 +02:00
|
|
|
|
2020-04-01 21:35:24 +02:00
|
|
|
TimelineErr(TimelineErr),
|
2020-04-11 04:36:03 +02:00
|
|
|
EventErr(EventErr),
|
2020-04-01 21:35:24 +02:00
|
|
|
RedisParseErr(RedisParseErr),
|
|
|
|
RedisConnErr(RedisConnErr),
|
2020-04-11 04:36:03 +02:00
|
|
|
ChannelSendErr(tokio::sync::watch::error::SendError<(Timeline, Event)>),
|
2020-04-24 01:28:26 +02:00
|
|
|
ChannelSendErr2(tokio::sync::mpsc::error::UnboundedTrySendError<Event>),
|
2020-04-01 21:35:24 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl std::error::Error for Error {}
|
2020-04-11 04:36:03 +02:00
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl fmt::Display for Error {
|
2020-04-01 21:35:24 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
2020-04-22 20:38:22 +02:00
|
|
|
use Error::*;
|
2020-04-01 21:35:24 +02:00
|
|
|
match self {
|
2020-04-09 00:39:52 +02:00
|
|
|
InvalidId => write!(
|
|
|
|
f,
|
2020-04-24 01:28:26 +02:00
|
|
|
"tried to access a timeline/channel subscription that does not exist"
|
2020-04-09 00:39:52 +02:00
|
|
|
),
|
2020-04-01 21:35:24 +02:00
|
|
|
EventErr(inner) => write!(f, "{}", inner),
|
|
|
|
RedisParseErr(inner) => write!(f, "{}", inner),
|
|
|
|
RedisConnErr(inner) => write!(f, "{}", inner),
|
|
|
|
TimelineErr(inner) => write!(f, "{}", inner),
|
2020-04-11 04:36:03 +02:00
|
|
|
ChannelSendErr(inner) => write!(f, "{}", inner),
|
2020-04-24 01:28:26 +02:00
|
|
|
ChannelSendErr2(inner) => write!(f, "{}", inner),
|
2020-04-01 21:35:24 +02:00
|
|
|
}?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl From<tokio::sync::watch::error::SendError<(Timeline, Event)>> for Error {
|
2020-04-11 04:36:03 +02:00
|
|
|
fn from(error: tokio::sync::watch::error::SendError<(Timeline, Event)>) -> Self {
|
|
|
|
Self::ChannelSendErr(error)
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 01:28:26 +02:00
|
|
|
impl From<tokio::sync::mpsc::error::UnboundedTrySendError<Event>> for Error {
|
|
|
|
fn from(error: tokio::sync::mpsc::error::UnboundedTrySendError<Event>) -> Self {
|
|
|
|
Self::ChannelSendErr2(error)
|
|
|
|
}
|
|
|
|
}
|
2020-04-11 04:36:03 +02:00
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl From<EventErr> for Error {
|
2020-04-11 04:36:03 +02:00
|
|
|
fn from(error: EventErr) -> Self {
|
2020-04-01 21:35:24 +02:00
|
|
|
Self::EventErr(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl From<RedisConnErr> for Error {
|
2020-04-01 21:35:24 +02:00
|
|
|
fn from(e: RedisConnErr) -> Self {
|
|
|
|
Self::RedisConnErr(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl From<TimelineErr> for Error {
|
2020-04-01 21:35:24 +02:00
|
|
|
fn from(e: TimelineErr) -> Self {
|
|
|
|
Self::TimelineErr(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 20:38:22 +02:00
|
|
|
impl From<RedisParseErr> for Error {
|
2020-04-01 21:35:24 +02:00
|
|
|
fn from(e: RedisParseErr) -> Self {
|
|
|
|
Self::RedisParseErr(e)
|
|
|
|
}
|
|
|
|
}
|