simple 0.10.0.1 → 0.10.0.2
raw patch · 3 files changed
+31/−1 lines, 3 files
Files
- simple.cabal +2/−1
- src/Web/Simple.hs +2/−0
- src/Web/Simple/Controller/Exception.hs +27/−0
simple.cabal view
@@ -1,5 +1,5 @@ name: simple-version: 0.10.0.1+version: 0.10.0.2 synopsis: A minimalist web framework for the WAI server interface description: @@ -85,6 +85,7 @@ Web.Simple, Web.Simple.Auth, Web.Simple.Controller,+ Web.Simple.Controller.Exception, Web.Simple.Controller.Trans, Web.Simple.Responses, Web.Simple.Static,
src/Web/Simple.hs view
@@ -16,6 +16,7 @@ module Web.Simple ( module Web.Simple.Responses , module Web.Simple.Controller+ , module Web.Simple.Controller.Exception , module Web.Simple.Static , module Network.Wai -- * Overview@@ -34,6 +35,7 @@ import Network.Wai import Web.Simple.Responses import Web.Simple.Controller+import Web.Simple.Controller.Exception import Web.Simple.Static {- $Overview
+ src/Web/Simple/Controller/Exception.hs view
@@ -0,0 +1,27 @@+module Web.Simple.Controller.Exception where++import qualified Control.Exception as E+import Control.Monad.Trans.Control+import Web.Simple.Controller++onException :: Controller s a -> Controller s b -> Controller s a+onException act handler = control $ \runInM -> do+ runInM act `E.onException` runInM handler++finally :: Controller s a -> Controller s b -> Controller s a+finally act handler = do+ res <- (act `onException` handler)+ handler+ return res++bracket :: Controller s a -> (a -> Controller s b)+ -> (a -> Controller s c) -> Controller s c+bracket aquire release act = do+ a <- aquire+ act a `finally` release a++handle :: E.Exception e => (e -> Controller s a) -> Controller s a+ -> Controller s a+handle handler act = control $ \runInM -> do+ E.handle (runInM . handler) $ runInM act+