-
Notifications
You must be signed in to change notification settings - Fork 30
/
error.rs
70 lines (57 loc) · 1.95 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::structure::GValue;
use thiserror::Error;
#[cfg(feature = "async_gremlin")]
use mobc;
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Error)]
pub enum GremlinError {
#[error("data store disconnected")]
Generic(String),
#[error(transparent)]
WebSocket(tungstenite::error::Error),
#[error(transparent)]
Pool(#[from] r2d2::Error),
#[error("Got wrong type {0:?}")]
WrongType(GValue),
#[error("Cast error: {0}")]
Cast(String),
#[error("JSON error: {0}")]
Json(String),
#[error("Request error: {0:?} ")]
Request((i16, String)),
#[error(transparent)]
Serde(#[from] serde_json::Error),
#[cfg(feature = "async_gremlin")]
#[error(transparent)]
WebSocketAsync(#[from] async_tungstenite::tungstenite::Error),
#[cfg(feature = "async_gremlin")]
#[error(transparent)]
ChannelSend(#[from] futures::channel::mpsc::SendError),
#[error(transparent)]
Uuid(#[from] uuid::Error),
}
#[cfg(feature = "async_gremlin")]
impl From<mobc::Error<GremlinError>> for GremlinError {
fn from(e: mobc::Error<GremlinError>) -> GremlinError {
match e {
mobc::Error::Inner(e) => e,
mobc::Error::BadConn => {
GremlinError::Generic(String::from("Async pool bad connection"))
}
mobc::Error::Timeout => GremlinError::Generic(String::from("Async pool timeout")),
}
}
}
#[cfg(not(feature = "async_gremlin"))]
impl From<tungstenite::error::Error> for GremlinError {
fn from(e: tungstenite::error::Error) -> GremlinError {
let error = match e {
tungstenite::error::Error::AlreadyClosed => tungstenite::error::Error::AlreadyClosed,
tungstenite::error::Error::ConnectionClosed => {
tungstenite::error::Error::ConnectionClosed
}
_ => return GremlinError::Generic(format!("Error from ws {}", e)),
};
GremlinError::WebSocket(error)
}
}