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
|
module Kino.UI (runApp) where
|
||||||
|
|
||||||
|
import Control.Exception
|
||||||
|
|
||||||
import Brick hiding (Direction(..))
|
import Brick hiding (Direction(..))
|
||||||
import Brick.Widgets.Edit (handleEditorEvent, editorText, editAttr, getEditContents)
|
import Brick.Widgets.Edit (handleEditorEvent, editorText, editAttr, getEditContents)
|
||||||
import Control.Monad.IO.Class (liftIO)
|
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
|
-- | Updates the state given a way to request a new movie listing
|
||||||
setMovies :: AppS -> IO (Either T.Text JSONListMovies) -> IO AppS
|
setMovies :: AppS -> IO (Either T.Text JSONListMovies) -> IO AppS
|
||||||
setMovies s mb = do
|
setMovies s mb = do
|
||||||
m <- mb
|
m <- try mb :: IO (Either SomeException (Either T.Text JSONListMovies))
|
||||||
case m of
|
pure $ case m of
|
||||||
(Left t) -> pure (displayMessage s True (T.unpack t))
|
(Left e) -> displayMessage s True (displayException e)
|
||||||
(Right l) -> pure (s & appListing .~ l
|
(Right r) -> case r of
|
||||||
|
(Left t) -> displayMessage s False (T.unpack t)
|
||||||
|
(Right l) -> s & appListing .~ l
|
||||||
& appCursor .~ 0
|
& appCursor .~ 0
|
||||||
& appDetails .~ (moviesMovies l !? 0))
|
& appDetails .~ (moviesMovies l !? 0)
|
||||||
|
|
||||||
-- | The starting event which grabs the inital listing
|
-- | The starting event which grabs the inital listing
|
||||||
startEvent :: AppS -> EventM Ident AppS
|
startEvent :: AppS -> EventM Ident AppS
|
||||||
|
|
Loading…
Reference in New Issue
Block a user