nitter_scraper/
error.rs

1use std::process::ExitCode;
2
3#[derive(Debug)]
4pub enum NitterError {
5    Parse(String),
6    Network(String),
7    ProtectedAccount,
8    SuspendedAccount,
9    NotFound,
10}
11
12impl std::fmt::Display for NitterError {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            Self::Parse(s) => write!(f, "unable to parse nitter: {}", s),
16            Self::Network(s) => write!(f, "unable to send request: {}", s),
17            Self::ProtectedAccount => write!(f, "account is protected"),
18            Self::SuspendedAccount => write!(f, "account is suspended"),
19            Self::NotFound => write!(f, "account not found"),
20        }
21    }
22}
23
24impl NitterError {
25    pub fn exit_code(&self) -> ExitCode {
26        match self {
27            Self::ProtectedAccount | Self::SuspendedAccount | Self::NotFound => ExitCode::from(10),
28            _ => ExitCode::FAILURE,
29        }
30    }
31}
32
33impl std::error::Error for NitterError {}