From 43b8ccb52ea82160a390831dec0b94ecfb2682a6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 9 Feb 2024 10:57:12 +0100 Subject: [PATCH] :sparkles: Improve error handling on websocket code --- backend/src/app/util/websocket.clj | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/app/util/websocket.clj b/backend/src/app/util/websocket.clj index 38276e743..70d8eb406 100644 --- a/backend/src/app/util/websocket.clj +++ b/backend/src/app/util/websocket.clj @@ -15,6 +15,7 @@ [app.util.time :as dt] [promesa.exec :as px] [promesa.exec.csp :as sp] + [promesa.util :as pu] [ring.request :as rreq] [ring.websocket :as rws] [yetti.websocket :as yws]) @@ -185,17 +186,18 @@ (rws/send channel message) (recur i)))))) - (catch java.nio.channels.ClosedChannelException _) - (catch java.net.SocketException _) - (catch java.io.IOException _) - (catch InterruptedException _cause (l/dbg :hint "websocket thread interrumpted" :conn-id id)) (catch Throwable cause - (l/err :hint "unhandled exception on websocket thread" - :conn-id id - :cause cause)) + (let [cause (pu/unwrap-exception cause)] + (if (or (instance? java.nio.channels.ClosedChannelException cause) + (instance? java.net.SocketException cause) + (instance? java.io.IOException cause)) + nil + (l/err :hint "unhandled exception on websocket thread" + :conn-id id + :cause cause)))) (finally (try (handler wsp {:type :close})