waybackmachine_client/
errors.rs

1use std::fmt;
2
3/// Errors that can occur during archiving.
4#[derive(Debug, Eq, PartialEq)]
5pub enum Error {
6    InvalidUrl(String),
7    RequestFailed(String),
8    CannotArchive(String, String),
9    CannotCheckArchive(String),
10    NoRecentArchive(String),
11    ExcludedUrl(String),
12}
13
14impl fmt::Display for Error {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Error::InvalidUrl(input) => write!(f, "Invalid URL: {}", input),
18            Error::RequestFailed(err) => write!(f, "Request failed: {}", err),
19            Error::CannotArchive(code, url) => write!(f, "Failed ({}): {}", code, url),
20            Error::CannotCheckArchive(error) => write!(f, "Failed to get archive: {}", error),
21            Error::NoRecentArchive(url) => write!(f, "No recent archive exists: {}", url),
22            Error::ExcludedUrl(url) => write!(f, "Excluded URL: {}", url),
23        }
24    }
25}
26
27impl From<reqwest_middleware::Error> for Error {
28    fn from(err: reqwest_middleware::Error) -> Self {
29        Error::RequestFailed(err.to_string())
30    }
31}
32
33impl From<reqwest::Error> for Error {
34    fn from(err: reqwest::Error) -> Self {
35        Error::RequestFailed(err.to_string())
36    }
37}
38
39impl From<chrono::ParseError> for Error {
40    fn from(err: chrono::ParseError) -> Self {
41        Error::CannotCheckArchive(err.to_string())
42    }
43}