worterbuch_client/
error.rs

1/*
2 *  Worterbuch client errors module
3 *
4 *  Copyright (C) 2024 Michael Bachmann
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU Affero General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU Affero General Public License for more details.
15 *
16 *  You should have received a copy of the GNU Affero General Public License
17 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20use std::fmt;
21#[cfg(feature = "tokio")]
22use tokio::sync::broadcast;
23use worterbuch_common::Err;
24
25#[derive(Debug)]
26pub enum SubscriptionError {
27    #[cfg(feature = "tokio")]
28    RecvError(broadcast::error::RecvError),
29    ServerError(Err),
30    SerdeError(serde_json::Error),
31}
32
33impl fmt::Display for SubscriptionError {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            #[cfg(feature = "tokio")]
37            SubscriptionError::RecvError(e) => e.fmt(f),
38            SubscriptionError::ServerError(e) => e.fmt(f),
39            SubscriptionError::SerdeError(e) => e.fmt(f),
40        }
41    }
42}
43
44impl std::error::Error for SubscriptionError {}
45
46impl From<serde_json::Error> for SubscriptionError {
47    fn from(e: serde_json::Error) -> Self {
48        Self::SerdeError(e)
49    }
50}