]> andersk Git - scripts-static-cat.git/commitdiff
Clean up open exception handling.
authorAnders Kaseorg <andersk@mit.edu>
Tue, 9 Mar 2010 05:52:03 +0000 (00:52 -0500)
committerAnders Kaseorg <andersk@mit.edu>
Tue, 9 Mar 2010 05:53:29 +0000 (00:53 -0500)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
StaticCat.hs

index 25be38899a5b007ca43395beb61afa3138e57145..be7fbe0ceccb1d4fd4b79221808c58e3992246ea 100644 (file)
@@ -131,13 +131,15 @@ serveFile file = (`catchExceptionCGI` outputMyError) $ do
 
   checkMethod $ do
 
-  h <- (`catchExceptionCGI` \e ->
-            if isDoesNotExistError e then throwExceptionCGI NotFound
-            else if isPermissionError e then throwExceptionCGI Forbidden
-            else throwExceptionCGI e) $
-        liftIO $ openBinaryFile file ReadMode
-  (`catchCGI` \e ->
-       (liftIO $ hClose h) >> throwCGI e) $ do
+  let handleOpenError e =
+          if isDoesNotExistError e then throwExceptionCGI NotFound
+          else if isPermissionError e then throwExceptionCGI Forbidden
+          else throwExceptionCGI e
+  h <- liftIO (openBinaryFile file ReadMode) `catchExceptionCGI` handleOpenError
+  let handlePostOpenError e = do
+        liftIO $ hClose h
+        throwCGI e
+  (`catchCGI` handlePostOpenError) $ do
 
   status <- liftIO $ hGetStatus h
   let mTime = modificationTime status
This page took 1.12199 seconds and 5 git commands to generate.