aboutsummaryrefslogblamecommitdiffstats
path: root/src/error.rs
blob: 81cadd1264c2155573af0c6f2c946f756bca2c48 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                      


                           


                                                                   



                                                                 
                          



                                            
                                                  




                                                 
                                                       




                                                   
                                                      

     

















                                                          
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),
    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)
    }
}