1#[cfg(any(feature = "auth"))]
2pub mod creation {
3 use std::{error::Error as StdError, fmt};
4
5 #[derive(Debug)]
6 pub(crate) enum CreationErrorKind {
7 #[cfg(feature = "enterprise")]
8 BaseUrlWithoutProtocol,
9 #[cfg(feature = "enterprise")]
10 BaseUrlWithoutApiPath,
11 #[cfg(feature = "auth")]
12 AuthTokenNotProvided,
13 #[cfg(feature = "enterprise")]
14 BaseUrlNotProvided,
15 }
16
17 #[derive(Debug)]
18 pub struct CreationError {
19 pub(crate) kind: CreationErrorKind,
20 }
21
22 impl CreationError {
23 fn new(kind: CreationErrorKind) -> Self {
24 Self { kind }
25 }
26
27 #[cfg(feature = "enterprise")]
28 pub(crate) fn base_url_without_protocol() -> Self {
29 Self::new(CreationErrorKind::BaseUrlWithoutProtocol)
30 }
31
32 #[cfg(feature = "enterprise")]
33 pub(crate) fn base_url_without_api_path() -> Self {
34 Self::new(CreationErrorKind::BaseUrlWithoutApiPath)
35 }
36
37 #[cfg(feature = "auth")]
38 pub(crate) fn auth_token_not_provided() -> Self {
39 Self::new(CreationErrorKind::AuthTokenNotProvided)
40 }
41
42 #[cfg(feature = "enterprise")]
43 pub(crate) fn base_url_not_provided() -> Self {
44 Self::new(CreationErrorKind::BaseUrlNotProvided)
45 }
46 }
47
48 impl StdError for CreationError {}
49
50 impl fmt::Display for CreationError {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match &self.kind {
53 #[cfg(feature = "enterprise")]
54 CreationErrorKind::BaseUrlWithoutProtocol => {
55 write!(f, "Base URL is without the protocol.")
56 }
57
58 #[cfg(feature = "enterprise")]
59 CreationErrorKind::BaseUrlWithoutApiPath => {
60 write!(f, "Base URL is without the `/api/v3` path at the end.")
61 }
62 #[cfg(feature = "auth")]
63 CreationErrorKind::AuthTokenNotProvided => {
64 write!(f, "Auth token not provided")
65 }
66 #[cfg(feature = "enterprise")]
67 CreationErrorKind::BaseUrlNotProvided => {
68 write!(f, "Base URL is not provided.")
69 }
70 }
71 }
72 }
73 #[cfg(test)]
74 mod tests {
75 use crate::CreationError;
76
77 fn assert_sync<T: Sync>() {}
78 fn assert_send<T: Send>() {}
79
80 #[test]
81 fn test_send_and_sync() {
82 assert_sync::<CreationError>();
83 assert_send::<CreationError>();
84 }
85 }
86}
87
88pub mod runtime {
89 use std::{error::Error as StdError, fmt};
90
91 #[derive(Debug)]
92 pub(crate) enum RuntimeErrorKind {
93 #[cfg(feature = "auth")]
94 BadCredentials,
95 NotFound,
96 }
97
98 #[derive(Debug)]
99 pub struct RuntimeError {
100 pub(crate) kind: RuntimeErrorKind,
101 }
102
103 impl RuntimeError {
104 fn new(kind: RuntimeErrorKind) -> Self {
105 Self { kind }
106 }
107
108 #[cfg(feature = "auth")]
109 pub(crate) fn bad_credentials() -> Self {
110 Self::new(RuntimeErrorKind::BadCredentials)
111 }
112
113 pub(crate) fn not_found() -> Self {
114 Self::new(RuntimeErrorKind::NotFound)
115 }
116 }
117
118 impl StdError for RuntimeError {}
119
120 impl fmt::Display for RuntimeError {
121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122 match &self.kind {
123 #[cfg(feature = "auth")]
124 RuntimeErrorKind::BadCredentials => {
125 write!(f, "Bad credentials")
126 }
127 RuntimeErrorKind::NotFound => {
128 write!(f, "Either the resource does not exist, or it is protected")
129 }
130 }
131 }
132 }
133 #[cfg(test)]
134 mod tests {
135 use crate::RuntimeError;
136
137 fn assert_sync<T: Sync>() {}
138 fn assert_send<T: Send>() {}
139
140 #[test]
141 fn test_send_and_sync() {
142 assert_sync::<RuntimeError>();
143 assert_send::<RuntimeError>();
144 }
145 }
146}