summaryrefslogtreecommitdiff
path: root/src/server/FastCGIUtils.hs
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-08-24 19:12:44 +0000
committerbjorn <bjorn@bringert.net>2008-08-24 19:12:44 +0000
commita8f054657448348ef8564d06958269fd4cf1adb9 (patch)
tree71f5fbf501251e923e066ec6fd5008f251517568 /src/server/FastCGIUtils.hs
parent5c0487200f2642ffe597431ae4f685a0f35d35f1 (diff)
Move CGIError stuff to FastCGIUtils.
Diffstat (limited to 'src/server/FastCGIUtils.hs')
-rw-r--r--src/server/FastCGIUtils.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs
index 762127f7c..2cf64af91 100644
--- a/src/server/FastCGIUtils.hs
+++ b/src/server/FastCGIUtils.hs
@@ -1,9 +1,12 @@
+{-# LANGUAGE DeriveDataTypeable #-}
module FastCGIUtils (initFastCGI, loopFastCGI,
- DataRef, newDataRef, getData) where
+ DataRef, newDataRef, getData,
+ throwCGIError, handleCGIErrors) where
import Control.Concurrent
import Control.Exception
import Control.Monad
+import Data.Dynamic
import Data.IORef
import Prelude hiding (catch)
import System.Directory
@@ -14,6 +17,7 @@ import System.IO.Unsafe
import System.Posix
import System.Time
+
import Network.FastCGI
initFastCGI :: IO ()
@@ -119,4 +123,19 @@ getData loadData ref file = liftIO $
-- Logging
logError :: String -> IO ()
-logError s = hPutStrLn stderr s \ No newline at end of file
+logError s = hPutStrLn stderr s
+
+-- * General CGI Error exception mechanism
+
+data CGIError = CGIError { cgiErrorCode :: Int, cgiErrorMessage :: String, cgiErrorText :: [String] }
+ deriving Typeable
+
+throwCGIError :: Int -> String -> [String] -> CGI a
+throwCGIError c m t = throwCGI $ DynException $ toDyn $ CGIError c m t
+
+handleCGIErrors :: CGI CGIResult -> CGI CGIResult
+handleCGIErrors x = x `catchCGI` \e -> case e of
+ DynException d -> case fromDynamic d of
+ Nothing -> throw e
+ Just (CGIError c m t) -> outputError c m t
+ _ -> throw e