aboutsummaryrefslogtreecommitdiffstats
path: root/src/error.rs
blob: 42c01b1c11c1e3277f3e32c6fe90c609cb53c50e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::string::FromUtf8Error;

use rocket::{http::Status, Responder};

#[derive(Responder, Debug)]
pub enum BlossomError {
    Reqwest(Status, #[response(ignore)] reqwest::Error),
    ListenBrainz(Status, #[response(ignore)] listenbrainz::Error),
    Skinnyverse(Status, #[response(ignore)] mastodon_async::Error),
    Chrono(Status, #[response(ignore)] chrono::ParseError),
    Io(Status, #[response(ignore)] std::io::Error),
    Deserialization(Status, #[response(ignore)] toml::de::Error),
    Syndicator(Status, #[response(ignore)] atom_syndication::Error),
    Utf8Conversion(Status, #[response(ignore)] FromUtf8Error),
    NotFound(Status),
    NoMetadata(Status),
    Unimplemented(Status),
}

impl From<reqwest::Error> for BlossomError {
    fn from(e: reqwest::Error) -> Self {
        BlossomError::Reqwest(Status::new(500), e)
    }
}

impl From<listenbrainz::Error> for BlossomError {
    fn from(e: listenbrainz::Error) -> Self {
        BlossomError::ListenBrainz(Status::new(500), e)
    }
}

impl From<mastodon_async::Error> for BlossomError {
    fn from(e: mastodon_async::Error) -> Self {
        BlossomError::Skinnyverse(Status::new(500), e)
    }
}

impl From<chrono::ParseError> for BlossomError {
    fn from(e: chrono::ParseError) -> Self {
        BlossomError::Chrono(Status::new(500), e)
    }
}

impl From<std::io::Error> for BlossomError {
    fn from(e: std::io::Error) -> Self {
        BlossomError::Io(Status::new(500), e)
    }
}

impl From<toml::de::Error> for BlossomError {
    fn from(e: toml::de::Error) -> Self {
        BlossomError::Deserialization(Status::new(500), e)
    }
}

impl From<atom_syndication::Error> for BlossomError {
    fn from(e: atom_syndication::Error) -> Self {
        BlossomError::Syndicator(Status::new(500), e)
    }
}

impl From<FromUtf8Error> for BlossomError {
    fn from(e: FromUtf8Error) -> Self {
        BlossomError::Utf8Conversion(Status::new(500), e)
    }
}