From 668c564927c7c5e2487415b773fe3c66f17fcc9a Mon Sep 17 00:00:00 2001 From: Allan Clements Date: Mon, 5 Aug 2024 21:00:28 -0500 Subject: [PATCH] Map additional tungstenite errors to GremlinError::WebSocketAsync --- gremlin-client/src/aio/error.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gremlin-client/src/aio/error.rs b/gremlin-client/src/aio/error.rs index 5861c77b..152aaeb3 100644 --- a/gremlin-client/src/aio/error.rs +++ b/gremlin-client/src/aio/error.rs @@ -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)