Luke Plant avatar Luke Plant committed 6bca1fd

Made 'notFoundHandler' into type 'View' for simplicity

Comments (0)

Files changed (1)

src/Ella/Framework.hs

 import Ella.Param
 import Ella.Response
 import Ella.Request
+import Maybe (fromJust)
 import System.IO (stdout, hClose)
 import qualified Data.ByteString.Lazy as BS
 
 
 -- | Options for the dispatch process
 data DispatchOptions = DispatchOptions {
-      notFoundHandler :: Request -> IO Response
-    -- ^ function that will return a 404 page in the case of no view functions matching
+      notFoundHandler :: View
+    -- ^ function that will return a 404 page in the case of no view functions matching.
+    -- It is defined as 'View' for simplicity - it should always return 'Just' something.
     , requestOptions :: RequestOptions
     -- ^ options passed to 'buildCGIRequest'
     , viewProcessors :: [View -> View]
 -- | A set of DispatchOptions useful as a basis.
 defaultDispatchOptions :: DispatchOptions
 defaultDispatchOptions = DispatchOptions {
-                           notFoundHandler = const $ return $ default404
+                           notFoundHandler = const $ return $ Just default404
                          , requestOptions = defaultRequestOptions
                          , viewProcessors = []
                          }
             -> IO ()
 dispatchCGI views opts = do
   req <- buildCGIRequest (requestOptions opts)
-  resp' <- (apply (viewProcessors opts) $ dispatchRequest views) req
-  resp <- case resp' of
-            Nothing -> notFoundHandler opts $ req
-            Just x -> return x
-  sendResponseCGI resp
+  m_resp <- (apply (viewProcessors opts) $ dispatchRequest $ views ++ [notFoundHandler opts]) req
+  sendResponseCGI $ fromJust m_resp
 
 
 -- Routing
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.