1use thiserror::Error;
2use ugc_scraper_types::MallFormedTransaction;
3
4#[derive(Debug, Error)]
5pub enum ScrapeError {
6 #[error("Failed to request data: {0:#}")]
7 Request(#[from] reqwest::Error),
8 #[error(transparent)]
9 Parse(#[from] ParseError),
10 #[error("Player or team doesn't exist")]
11 NotFound,
12}
13
14#[derive(Debug, Error, Clone)]
15pub enum ParseError {
16 #[error("Couldn't find expected element '{selector}' for {role}")]
17 ElementNotFound {
18 selector: &'static str,
19 role: &'static str,
20 },
21 #[error("Element '{selector}' does contain text for {role}")]
22 EmptyText {
23 selector: &'static str,
24 role: &'static str,
25 },
26 #[error("Invalid text for {role}: {text}")]
27 InvalidText { text: String, role: &'static str },
28 #[error("Invalid link for {role}: {link}")]
29 InvalidLink { link: String, role: &'static str },
30 #[error("Invalid date for {role}: {date}")]
31 InvalidDate { date: String, role: &'static str },
32}
33
34impl From<MallFormedTransaction> for ParseError {
35 fn from(transaction: MallFormedTransaction) -> Self {
36 ParseError::InvalidText {
37 role: "transaction",
38 text: transaction.text,
39 }
40 }
41}
42
43impl From<MallFormedTransaction> for ScrapeError {
44 fn from(transaction: MallFormedTransaction) -> Self {
45 ScrapeError::Parse(ParseError::from(transaction))
46 }
47}