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}
37
38impl Error for RequestError {}
39
40impl Display for RequestError {
41 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
42 match self {
43 RequestError::NotJSON => write!(f, "Invalid JSON"),
44 RequestError::NoUTF8 => write!(f, "Utf8 error"),
45 RequestError::NetworkError => write!(f, "Network error"),
46 RequestError::SerializeError => write!(f, "Serialize error"),
47 RequestError::NotFoundOrNullBody => write!(f, "Body is null or record is not found"),
48 }
49 }
50}
51
52#[derive(Debug)]
53pub enum ServerEventError {
54 ConnectionError,
55}
56
57impl Error for ServerEventError {}
58
59impl Display for ServerEventError {
60 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
61 match self {
62 ServerEventError::ConnectionError => write!(f, "Connection error for server events"),
63 }
64 }
65}