summaryrefslogtreecommitdiff
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
parent5c0487200f2642ffe597431ae4f685a0f35d35f1 (diff)
Move CGIError stuff to FastCGIUtils.
-rw-r--r--src/server/FastCGIUtils.hs23
-rw-r--r--src/server/MainFastCGI.hs17
2 files changed, 21 insertions, 19 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
diff --git a/src/server/MainFastCGI.hs b/src/server/MainFastCGI.hs
index b7af9fce4..5e9dd1cee 100644
--- a/src/server/MainFastCGI.hs
+++ b/src/server/MainFastCGI.hs
@@ -9,9 +9,7 @@ import Network.CGI
import Text.JSON
import qualified Codec.Binary.UTF8.String as UTF8 (encodeString)
-import Control.Exception
import Control.Monad
-import Data.Dynamic
import qualified Data.Map as Map
import Data.Maybe
@@ -127,21 +125,6 @@ linearize' pgf mto tree =
Nothing -> PGF.linearizeAllLang pgf tree
Just to -> [(to,PGF.linearize pgf to tree)]
--- * 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
-
-- * General CGI and JSON stuff
outputJSON :: JSON a => a -> CGI CGIResult