add exception handling for setMovies
This commit is contained in:
parent
d9ae2671d6
commit
9e833a2e5d
|
@ -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
|
||||
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))
|
||||
& appDetails .~ (moviesMovies l !? 0)
|
||||
|
||||
-- | The starting event which grabs the inital listing
|
||||
startEvent :: AppS -> EventM Ident AppS
|
||||
|
|
Loading…
Reference in New Issue
Block a user