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