odysee-dl

odysee.com channel content downloader
git clone https://git.ea.contact/odysee-dl
Log | Files | Refs | README

error.rs (880B)


      1 use core::fmt;
      2 
      3 #[derive(Debug)]
      4 pub enum Error {
      5     Http(String),
      6     InvalidUrl,
      7     Io(std::io::Error),
      8 }
      9 
     10 impl fmt::Display for Error {
     11     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     12         match self {
     13             Error::Http(err) => write!(f, "HTTP error: {}", err),
     14             Error::InvalidUrl => write!(f, "Invalid URL (expected https?://odysee\\.com/@[^:]+:\\d+.*)"),
     15             Error::Io(err) => write!(f, "IO error: {}", err),
     16         }
     17     }
     18 }
     19 
     20 impl From<ureq::Error> for Error {
     21     fn from(err: ureq::Error) -> Self {
     22         Error::Http(err.to_string())
     23     }
     24 }
     25 
     26 impl From<serde_json::Error> for Error {
     27     fn from(err: serde_json::Error) -> Self {
     28         Error::Http(err.to_string())
     29     }
     30 }
     31 
     32 impl From<std::io::Error> for Error {
     33     fn from(err: std::io::Error) -> Self {
     34         Error::Io(err)
     35     }
     36 }