From 1294a674bc465f630a134c0aca4eb8ea3b254521 Mon Sep 17 00:00:00 2001 From: Raphael Darley Date: Thu, 22 Aug 2024 08:45:11 -0700 Subject: [PATCH] improve ws reliability (#4584) --- src/rpc/response.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc/response.rs b/src/rpc/response.rs index 07cbc32b..04056edf 100644 --- a/src/rpc/response.rs +++ b/src/rpc/response.rs @@ -10,6 +10,7 @@ use surrealdb::channel::Sender; use surrealdb::rpc::format::Format; use surrealdb::rpc::Data; use surrealdb::sql::Value; +use surrealdb_core::rpc::RpcError; use tracing::Span; #[revisioned(revision = 1)] @@ -54,7 +55,14 @@ impl Response { span.record("rpc.error_message", err.message.as_ref()); } // Process the response for the format - let (len, msg) = fmt.res_ws(self).unwrap(); + let (len, msg) = match fmt.res_ws(self) { + Ok((l, m)) => (l, m), + Err(_) => { + let err: Failure = RpcError::Thrown("Serialisation Error".to_string()).into(); + fmt.res_ws(failure(None, err)) + .expect("Serialising known thrown error should succeed") + } + }; // Send the message to the write channel if chn.send(msg).await.is_ok() { record_rpc(cx.as_ref(), len, is_error);