Return ["CLOSED"] on failing subscriptions
This commit is contained in:
parent
97b0020a28
commit
ec0b068388
3 changed files with 38 additions and 3 deletions
|
@ -31,6 +31,12 @@ pub async fn client_connection(ws: WebSocket, context: Context, client_addr: Opt
|
|||
tokio::select! {
|
||||
Ok(message) = subscriber.recv() => {
|
||||
match message.content {
|
||||
crate::bussy::Command::ClientSubscriptionError(error_message) => {
|
||||
if let Some(sender) = &client.client_connection {
|
||||
log::info!("[Relay] sending [\"CLOSED\"] event to client: {}", client.client_id);
|
||||
if !sender.is_closed() {sender.send(Ok(Message::text(error_message))).unwrap()};
|
||||
}
|
||||
},
|
||||
crate::bussy::Command::PipelineResRelayMessageOk(client_id, relay_message) => {
|
||||
if client.client_id == client_id {
|
||||
if let Some(sender) = &client.client_connection {
|
||||
|
@ -226,7 +232,30 @@ async fn handle_req(
|
|||
let subscription = Subscription::new(subscription_id.clone(), filters);
|
||||
let needs_historical_events = subscription.needs_historical_events();
|
||||
|
||||
client.subscribe(subscription.clone()).unwrap();
|
||||
if let Err(subscription_error) = client.subscribe(subscription.clone()) {
|
||||
log::error!(
|
||||
"Error on handle_req. client IP: {:?}, message: {}",
|
||||
client.ip(),
|
||||
&subscription_error.message
|
||||
);
|
||||
let message = format!(
|
||||
"[\"CLOSED\", \"{}\", \"{}\"]",
|
||||
subscription_id, subscription_error.message
|
||||
);
|
||||
|
||||
context
|
||||
.pubsub
|
||||
.publish(
|
||||
channels::MSG_RELAY,
|
||||
crate::bussy::Message {
|
||||
source: channels::MSG_RELAY,
|
||||
content: crate::bussy::Command::ClientSubscriptionError(message),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
if needs_historical_events {
|
||||
context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue