improve ws reliability (#4584)

This commit is contained in:
Raphael Darley 2024-08-22 08:45:11 -07:00 committed by GitHub
parent 7c41aef3ba
commit 1294a674bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ use surrealdb::channel::Sender;
use surrealdb::rpc::format::Format; use surrealdb::rpc::format::Format;
use surrealdb::rpc::Data; use surrealdb::rpc::Data;
use surrealdb::sql::Value; use surrealdb::sql::Value;
use surrealdb_core::rpc::RpcError;
use tracing::Span; use tracing::Span;
#[revisioned(revision = 1)] #[revisioned(revision = 1)]
@ -54,7 +55,14 @@ impl Response {
span.record("rpc.error_message", err.message.as_ref()); span.record("rpc.error_message", err.message.as_ref());
} }
// Process the response for the format // 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 // Send the message to the write channel
if chn.send(msg).await.is_ok() { if chn.send(msg).await.is_ok() {
record_rpc(cx.as_ref(), len, is_error); record_rpc(cx.as_ref(), len, is_error);