File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ import qualified Control.Exception as Exception
26
26
import IHP.Controller.Context
27
27
import qualified Data.Aeson as Aeson
28
28
29
+ import qualified IHP.Log.Types as Log
30
+ import qualified IHP.Log as Log
31
+
29
32
class WSApp state where
30
33
initialState :: state
31
34
@@ -43,14 +46,15 @@ startWSApp connection = do
43
46
state <- newIORef (initialState @ state )
44
47
let ? state = state
45
48
let ? connection = connection
46
- let
47
- handleException Websocket. ConnectionClosed = pure ()
48
- handleException (Websocket. CloseRequest {}) = pure ()
49
- handleException e = error (" Unhandled Websocket exception: " <> show e)
50
- result <- Exception. try ((Websocket. withPingThread connection 30 (onPing @ state ) (run @ state )) `Exception.catch` handleException)
51
- onClose @ state
49
+
50
+ result <- Exception. try ((Websocket. withPingThread connection 30 (onPing @ state ) (run @ state )) `Exception.finally` onClose @ state )
52
51
case result of
53
- Left (Exception. SomeException e) -> putStrLn (tshow e)
52
+ Left (e@ Exception. SomeException {}) ->
53
+ case Exception. fromException e of
54
+ (Just Websocket. ConnectionClosed ) -> pure ()
55
+ (Just (Websocket. CloseRequest {})) -> pure ()
56
+ (Just other) -> error (" Unhandled Websocket exception: " <> show other)
57
+ Nothing -> Log. error (tshow e)
54
58
Right _ -> pure ()
55
59
56
60
setState :: (? state :: IORef state ) => state -> IO ()
You can’t perform that action at this time.
0 commit comments