diff options
Diffstat (limited to 'WebSockets.hs')
-rw-r--r-- | WebSockets.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/WebSockets.hs b/WebSockets.hs index 7750cf8..a220c68 100644 --- a/WebSockets.hs +++ b/WebSockets.hs @@ -44,6 +44,7 @@ import Data.Maybe import Text.Read import Control.Monad import Network.URI +import System.IO -- | Framing protocol used over a websocket connection. -- @@ -126,7 +127,7 @@ runClientApp :: URI -> ClientApp a -> IO (Maybe a) runClientApp serverurl app = do rv <- newEmptyTMVarIO let go conn = do - r <- app conn + r <- app conn `catch` showerr atomically $ putTMVar rv r catchJust catchconnclosed (runClientWith host port endpoint connectionOptions [] go) @@ -139,9 +140,15 @@ runClientApp serverurl app = do (':':s) -> fromMaybe 80 (readMaybe s) _ -> 80 endpoint = uriPath serverurl + catchconnclosed ConnectionClosed = Just () catchconnclosed _ = Nothing + showerr :: SomeException -> IO a + showerr e = do + hPutStrLn stderr (show e) + throwIO e + -- | Make a client that sends and receives AnyMessages over a websocket. clientApp :: Mode |