1use std::error::Error;
2use std::fmt::Display;
3use std::fmt;
4
5#[derive(Debug)]
6pub struct HttpError {
7 pub code: u16,
8 pub url: String,
9}
10
11#[derive(Debug)]
12pub enum HnError {
13 HtmlParsingError,
15 UnauthenticatedError,
18 AuthenticationError,
20 HttpError(HttpError),
22}
23
24impl Display for HnError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 HnError::HtmlParsingError => {
28 write!(f, "HtmlParsingErr: There was a problem parsing HTML data. This is an internal library error.")
29 },
30 HnError::UnauthenticatedError => {
31 write!(f, "UnauthenticatedError: An unauthenticated client attempted an action requiring authorization.")
32 }
33 HnError::AuthenticationError => {
34 write!(f, "A client failed to authenticate. Please check credential information, and authentication frequency")
35 }
36 HnError::HttpError(http_err) => {
37 write!(f, "A client failed during an HTTP request/response; url '{}', code '{}'",
38 http_err.url,
39 http_err.code,
40 )
41 }
42 }
43 }
44}
45
46
47impl Error for HnError {}