Skip to content

Commit

Permalink
Map additional tungstenite errors to GremlinError::WebSocketAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
criminosis committed Aug 6, 2024
1 parent f8f5fec commit 668c564
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gremlin-client/src/aio/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ use async_tungstenite::tungstenite;

impl From<&tungstenite::error::Error> for GremlinError {
fn from(e: &tungstenite::error::Error) -> GremlinError {
//Some of the tungstenite errors are cloneable or can be lightly recreated
//for those that cannot be, their message is wrapped in a GremlinError::Generic
//this does change the observed error type. In the future maybe sending tungstenite errors
//wrapped in an Arc can avoid this
let error = match e {
tungstenite::error::Error::AlreadyClosed => tungstenite::error::Error::AlreadyClosed,
tungstenite::error::Error::ConnectionClosed => {
tungstenite::error::Error::ConnectionClosed
}
tungstenite::Error::Protocol(e) => tungstenite::Error::Protocol(e.clone()),
tungstenite::Error::Utf8 => tungstenite::Error::Utf8,
tungstenite::Error::AttackAttempt => tungstenite::Error::AttackAttempt,
_ => return GremlinError::Generic(format!("Error from ws {}", e)),
};
GremlinError::WebSocketAsync(error)
Expand Down

0 comments on commit 668c564

Please sign in to comment.