1use crate::scrape;
2use crate::scrape::ScrapeError;
3use clerr::Report;
4use reqwest::StatusCode;
5use std::fmt::{Display, Formatter};
6use std::string::FromUtf8Error;
7use web_url::WebUrl;
8
9#[derive(Debug)]
11pub enum Error {
12 Other(Report),
14
15 InvalidString(FromUtf8Error),
17
18 InvalidResponseStatus(StatusCode),
20
21 InvalidURL { url: WebUrl, error_message: String },
23
24 Cache(file_storage::Error),
26
27 Source(reqwest::Error),
29
30 Scrape(scrape::ScrapeError),
32}
33
34impl From<Report> for Error {
35 fn from(report: Report) -> Self {
36 Self::Other(report)
37 }
38}
39
40impl From<FromUtf8Error> for Error {
41 fn from(error: FromUtf8Error) -> Self {
42 Self::InvalidString(error)
43 }
44}
45
46impl From<file_storage::Error> for Error {
47 fn from(error: file_storage::Error) -> Self {
48 Self::Cache(error)
49 }
50}
51
52impl From<reqwest::Error> for Error {
53 fn from(error: reqwest::Error) -> Self {
54 Self::Source(error)
55 }
56}
57
58impl From<ScrapeError> for Error {
59 fn from(error: ScrapeError) -> Self {
60 Self::Scrape(error)
61 }
62}
63
64impl Display for Error {
65 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
66 write!(f, "{:?}", self)
67 }
68}
69
70impl std::error::Error for Error {}