1use std::io;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Error, Debug)]
11pub enum Error {
12 #[error("IO error: {0}")]
14 Io(io::Error),
15
16 #[error("Certificate error: {0}")]
18 CertificateError(String),
19
20 #[error("TLS error: {0}")]
22 TlsError(String),
23
24 #[error("HTTP error: {0}")]
26 HttpError(http::Error),
27
28 #[error("Slinger error: {0}")]
30 SlingerError(slinger::Error),
31
32 #[error("Proxy error: {0}")]
34 ProxyError(String),
35
36 #[error("Invalid request: {0}")]
38 InvalidRequest(String),
39
40 #[error("Connection error: {0}")]
42 ConnectionError(String),
43
44 #[error("{0}")]
46 Other(String),
47}
48
49impl Error {
50 pub fn certificate_error(msg: impl Into<String>) -> Self {
52 let error = Error::CertificateError(msg.into());
53 tracing::error!("Certificate error: {}", error);
54 error
55 }
56
57 pub fn tls_error(msg: impl Into<String>) -> Self {
59 let error = Error::TlsError(msg.into());
60 tracing::error!("TLS error: {}", error);
61 error
62 }
63
64 pub fn proxy_error(msg: impl Into<String>) -> Self {
66 let error = Error::ProxyError(msg.into());
67 tracing::error!("Proxy error: {}", error);
68 error
69 }
70
71 pub fn invalid_request(msg: impl Into<String>) -> Self {
73 let error = Error::InvalidRequest(msg.into());
74 tracing::error!("Invalid request: {}", error);
75 error
76 }
77
78 pub fn connection_error(msg: impl Into<String>) -> Self {
80 let error = Error::ConnectionError(msg.into());
81 tracing::error!("Connection error: {}", error);
82 error
83 }
84
85 pub fn other(msg: impl Into<String>) -> Self {
87 let error = Error::Other(msg.into());
88 tracing::error!("Other error: {}", error);
89 error
90 }
91}
92
93impl From<io::Error> for Error {
94 fn from(value: io::Error) -> Self {
95 let error = Error::Io(value);
96 tracing::error!("IO error: {}", error);
97 error
98 }
99}
100
101impl From<http::Error> for Error {
102 fn from(value: http::Error) -> Self {
103 let error = Error::HttpError(value);
104 tracing::error!("HTTP error: {}", error);
105 error
106 }
107}
108
109impl From<slinger::Error> for Error {
110 fn from(value: slinger::Error) -> Self {
111 let error = Error::SlingerError(value);
112 tracing::error!("Slinger error: {}", error);
113 error
114 }
115}