From 9e833a2e5d1385f078ad5b26ca8e90f837795474 Mon Sep 17 00:00:00 2001 From: depsterr Date: Mon, 20 Sep 2021 14:31:54 +0200 Subject: [PATCH] add exception handling for setMovies --- src/Kino/UI.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Kino/UI.hs b/src/Kino/UI.hs index 60b5a21..112cd72 100644 --- a/src/Kino/UI.hs +++ b/src/Kino/UI.hs @@ -9,6 +9,8 @@ This is the code which interacts with Brick module Kino.UI (runApp) where +import Control.Exception + import Brick hiding (Direction(..)) import Brick.Widgets.Edit (handleEditorEvent, editorText, editAttr, getEditContents) import Control.Monad.IO.Class (liftIO) @@ -57,12 +59,14 @@ runApp = defaultMain app initialState -- | Updates the state given a way to request a new movie listing setMovies :: AppS -> IO (Either T.Text JSONListMovies) -> IO AppS setMovies s mb = do - m <- mb - case m of - (Left t) -> pure (displayMessage s True (T.unpack t)) - (Right l) -> pure (s & appListing .~ l - & appCursor .~ 0 - & appDetails .~ (moviesMovies l !? 0)) + m <- try mb :: IO (Either SomeException (Either T.Text JSONListMovies)) + pure $ case m of + (Left e) -> displayMessage s True (displayException e) + (Right r) -> case r of + (Left t) -> displayMessage s False (T.unpack t) + (Right l) -> s & appListing .~ l + & appCursor .~ 0 + & appDetails .~ (moviesMovies l !? 0) -- | The starting event which grabs the inital listing startEvent :: AppS -> EventM Ident AppS