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