diff options
| author | hallgren <hallgren@chalmers.se> | 2014-06-20 17:28:02 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2014-06-20 17:28:02 +0000 |
| commit | 9eb6557376dc69f3ec5db758fd6578b4cb8f3e3c (patch) | |
| tree | e902f8724eb6738cc1fa537caafa2d92fa54f783 /src | |
| parent | ef20e8cbac41246ce557053e0fac67aede1a9735 (diff) | |
PGF Service: return error code 404 (not found) instead of 500 (internal server error) for missing grammars
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/PGFService.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index b25e8a86d..c7518e19e 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -37,6 +37,7 @@ import System.Random import System.Process import System.Exit import System.IO +import System.IO.Error(isDoesNotExistError) import System.Directory(removeFile) import System.Mem(performGC) import Fold(fold) -- transfer function for OpenMath LaTeX @@ -82,14 +83,21 @@ cgiMain' cache path = do command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString)) (getInput "command") case command of - "download" -> outputBinary =<< liftIO (BS.readFile path) + "download" -> outputBinary =<< getFile BS.readFile path 'c':'-':_ -> #ifdef C_RUNTIME - cpgfMain command =<< liftIO (readCache' (snd cache) path) + cpgfMain command =<< getFile (readCache' (snd cache)) path #else serverError "Server configured without C run-time support" "" #endif - _ -> pgfMain command =<< liftIO (readCache' (fst cache) path) + _ -> pgfMain command =<< getFile (readCache' (fst cache)) path + +getFile get path = + either failed return =<< liftIO (E.try (get path)) + where + failed e = if isDoesNotExistError e + then notFound path + else liftIO $ ioError e -------------------------------------------------------------------------------- -- * C run-time functionality @@ -435,6 +443,7 @@ toBool s = s `elem` ["","yes","true","True"] missing = badRequest "Missing parameter" errorMissingId = badRequest "Missing identifier" "" +notFound = throw 404 "Not found" badRequest = throw 400 serverError = throw 500 |
