1use std::{
2 error::Error,
3 fmt::{Display, Formatter},
4};
5
6pub type UrlParseResult<T> = Result<T, UrlParseError>;
7
8#[derive(Debug)]
9pub enum UrlParseError {
10 NoPath,
11 NotHttps,
12 Parser(url::ParseError),
13}
14
15impl Error for UrlParseError {}
16
17impl Display for UrlParseError {
18 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19 match self {
20 UrlParseError::NoPath => write!(f, "URL path is missing."),
21 UrlParseError::NotHttps => write!(f, "The URL protocol should be https."),
22 UrlParseError::Parser(e) => write!(f, "Error while parsing the URL: {}", e),
23 }
24 }
25}
26
27pub type RequestResult<T> = Result<T, RequestError>;
28
29#[derive(Debug)]
30pub enum RequestError {
31 NotJSON,
32 NoUTF8,
33 NetworkError,
34 SerializeError,
35 NotFoundOrNullBody,
36 Unauthorized,
37}
38
39impl Error for RequestError {}
40
41impl Display for RequestError {
42 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
43 match self {
44 RequestError::NotJSON => write!(f, "Invalid JSON"),
45 RequestError::NoUTF8 => write!(f, "Utf8 error"),
46 RequestError::NetworkError => write!(f, "Network error"),
47 RequestError::SerializeError => write!(f, "Serialize error"),
48 RequestError::NotFoundOrNullBody => write!(f, "Body is null or record is not found"),
49 RequestError::Unauthorized => write!(f, "Unauthorized"),
50 }
51 }
52}
53
54#[derive(Debug)]
55pub enum ServerEventError {
56 ConnectionError,
57}
58
59impl Error for ServerEventError {}
60
61impl Display for ServerEventError {
62 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
63 match self {
64 ServerEventError::ConnectionError => write!(f, "Connection error for server events"),
65 }
66 }
67}