1use std::fmt::{Display, Formatter};
2use std::string::FromUtf8Error;
3
4use clerr::Report;
5use reqwest::StatusCode;
6use web_url::WebUrl;
7
8use crate::scrape::ScrapeError;
9
10#[derive(Debug)]
12pub enum Error {
13 Storage(file_storage::Error),
15
16 InvalidURL { url: WebUrl, error_message: String },
18
19 InvalidURLString {
21 url: String,
22 error: web_url::parse::Error,
23 },
24
25 InvalidText(FromUtf8Error),
27
28 Protocol(reqwest::Error),
30
31 InvalidResponseStatus(StatusCode),
33
34 Scrape(ScrapeError),
36
37 Other(Report),
39}
40
41impl From<file_storage::Error> for Error {
42 fn from(error: file_storage::Error) -> Self {
43 Self::Storage(error)
44 }
45}
46
47impl From<FromUtf8Error> for Error {
48 fn from(error: FromUtf8Error) -> Self {
49 Self::InvalidText(error)
50 }
51}
52
53impl From<reqwest::Error> for Error {
54 fn from(error: reqwest::Error) -> Self {
55 Self::Protocol(error)
56 }
57}
58
59impl From<ScrapeError> for Error {
60 fn from(error: ScrapeError) -> Self {
61 Self::Scrape(error)
62 }
63}
64
65impl From<Report> for Error {
66 fn from(report: Report) -> Self {
67 Self::Other(report)
68 }
69}
70
71impl Display for Error {
72 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
73 write!(f, "{:?}", self)
74 }
75}
76
77impl std::error::Error for Error {}