1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ScrapeError {
    #[error("Failed to request data: {0:#}")]
    Request(#[from] reqwest::Error),
    #[error(transparent)]
    Parse(#[from] ParseError),
    #[error("Player or team doesn't exist")]
    NotFound,
}

#[derive(Debug, Error, Clone)]
pub enum ParseError {
    #[error("Couldn't find expected element '{selector}' for {role}")]
    ElementNotFound {
        selector: &'static str,
        role: &'static str,
    },
    #[error("Element '{selector}' does contain text for {role}")]
    EmptyText {
        selector: &'static str,
        role: &'static str,
    },
    #[error("Invalid text for {role}: {text}")]
    InvalidText { text: String, role: &'static str },
    #[error("Invalid link for {role}: {link}")]
    InvalidLink { link: String, role: &'static str },
    #[error("Invalid date for {role}: {date}")]
    InvalidDate { date: String, role: &'static str },
}