1{-# LANGUAGE OverloadedStrings #-}
3module ExceptionSpec (main, spec) where
5import Control.Applicative
7import Control.Concurrent (forkIO, threadDelay)
10import Network.HTTP.Types hiding (Header)
11import Network.Wai hiding (Response)
12import Network.Wai.Internal (Request(..))
13import Network.Wai.Handler.Warp
14import System.IO.Unsafe (unsafePerformIO)
25testApp (Network.Wai.Internal.Request {pathInfo = [x]})
26 | x == "statusError" =
27 return $ responseLBS undefined [] "foo"
28 | x == "headersError" =
29 return $ responseLBS ok200 undefined "foo"
30 | x == "headerError" =
31 return $ responseLBS ok200 [undefined] "foo"
33 return $ responseLBS ok200 [] undefined
34 | x == "ioException" = do
35 void $ fail "ioException"
36 return $ responseLBS ok200 [] "foo"
38 return $ responseLBS ok200 [] "foo"
41spec = unsafePerformIO $ (forkIO testServer >> threadDelay 100000 >>) $ return $
42 describe "responds even if there is an exception" $ do
44 sc <- rspCode <$> sendGET "http://localhost:2345/statusError"
46 it "headersError" $ do
47 sc <- rspCode <$> sendGET "http://localhost:2345/headersError"
50 sc <- rspCode <$> sendGET "http://localhost:2345/headerError"
53 sc <- rspCode <$> sendGET "http://localhost:2345/bodyError"
56 sc <- rspCode <$> sendGET "http://localhost:2345/ioException"
59----------------------------------------------------------------
61sendGET :: String -> IO (Response String)
62sendGET url = sendGETwH url []
64sendGETwH :: String -> [Header] -> IO (Response String)
65sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
67unResult :: IO (Result (Response String)) -> IO (Response String)
71 Right rsp -> return rsp
72 Left _ -> error "Connection error"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list