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
use std::process::ExitCode;

#[derive(Debug)]
pub enum NitterError {
    Parse(String),
    Network(String),
    ProtectedAccount,
    SuspendedAccount,
    NotFound,
}

impl std::fmt::Display for NitterError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Parse(s) => write!(f, "unable to parse nitter: {}", s),
            Self::Network(s) => write!(f, "unable to send request: {}", s),
            Self::ProtectedAccount => write!(f, "account is protected"),
            Self::SuspendedAccount => write!(f, "account is suspended"),
            Self::NotFound => write!(f, "account not found"),
        }
    }
}

impl NitterError {
    pub fn exit_code(&self) -> ExitCode {
        match self {
            Self::ProtectedAccount | Self::SuspendedAccount | Self::NotFound => ExitCode::from(10),
            _ => ExitCode::FAILURE,
        }
    }
}

impl std::error::Error for NitterError {}