1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 Http(String),
6 Serialization(serde_json::Error),
7 Database(String),
8 Config(String),
9 NoRows,
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::Http(msg) => write!(f, "HTTP error: {msg}"),
16 Error::Serialization(err) => write!(f, "Serialization error: {err}"),
17 Error::Database(msg) => write!(f, "Database error: {msg}"),
18 Error::Config(msg) => write!(f, "Config error: {msg}"),
19 Error::NoRows => write!(f, "Query returned no rows"),
20 }
21 }
22}
23
24impl std::error::Error for Error {
25 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26 match self {
27 Error::Serialization(err) => Some(err),
28 _ => None,
29 }
30 }
31}
32
33impl From<serde_json::Error> for Error {
34 fn from(err: serde_json::Error) -> Self {
35 Error::Serialization(err)
36 }
37}