on master help sign in
Merge pull request #557 from mkscrg/clarify-warp-ex-handling

warp: add example of normal exception handling to Warp.hs haddocks

commit653b570268aecf3ea339d3145ad0b0e0094eb4aa authorMichael Snoyman <michael@snoyman.com> dateWed 25 May 2016, 07:01 (10 years ago) parent19a939ee251d8b
1 file changed+10−1
warp/Network/Wai/Handler/Warp.hs+10−1
warp/Network/Wai/Handler/Warp.hs+10−1
@@ -138,9 +138,18 @@ setOnException :: (Maybe Request -> SomeException -> IO ()) -> Settings -> Setti
138138setOnException x y = y { settingsOnException = x }
139139
140140-- | A function to create a `Response` when an exception occurs.
141−--
142141-- Default: 'defaultOnExceptionResponse'
143142--
143+-- Note that an application can handle its own exceptions without interfering with Warp:
144+--
145+-- > myApp :: Application
146+-- > myApp request respond = innerApp `catch` onError
147+-- > where
148+-- > onError = respond . response500 request
149+-- >
150+-- > response500 :: Request -> SomeException -> Response
151+-- > response500 req someEx = responseLBS status500 -- ...
152+--
144153-- Since 2.1.0
145154setOnExceptionResponse :: (SomeException -> Response) -> Settings -> Settings
146155setOnExceptionResponse x y = y { settingsOnExceptionResponse = x }