on master help sign in
refactoring respondOnException.
commit4a2278a89ad4a1eb7761eff309c6b340eecacad5 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 11 Oct 2013, 06:33 (13 years ago) parent80fb1f7
1 file changed+8−11
warp/Network/Wai/Handler/Warp/Run.hs+8−11
warp/Network/Wai/Handler/Warp/Run.hs+8−11
@@ -233,10 +233,17 @@ serveConnection :: T.Handle
233233 -> Cleaner
234234 -> Application -> Connection -> SockAddr-> IO ()
235235serveConnection timeoutHandle settings cleaner app conn remoteHost' =
236− respondOnException settings cleaner conn remoteHost' $ serveConnection'' $ connSource conn th
236+ (serveConnection'' $ connSource conn th) `onException` send500
237237 where
238238 th = threadHandle cleaner
239239
240+ send500 = void . mask $ \restore ->
241+ sendResponse settings cleaner dummyreq conn restore internalError
242+
243+ dummyreq = defaultRequest { remoteHost = remoteHost' }
244+
245+ internalError = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
246+
240247 serveConnection'' fromClient = do
241248 (env, getSource) <- parseRequest conn timeoutHandle remoteHost' fromClient
242249 case settingsIntercept settings env of
@@ -271,16 +278,6 @@ serveConnection timeoutHandle settings cleaner app conn remoteHost' =
271278 ResumableSource fromClient' _ <- liftIO getSource
272279 intercept fromClient' conn
273280
274−respondOnException :: Settings -> Cleaner -> Connection -> SockAddr -> IO () -> IO ()
275−respondOnException settings cleaner conn remoteHost' io = io `catch` \e@(SomeException _) -> do
276− mask $ \restore ->
277− void $ sendResponse settings cleaner defaultRequest
278− { remoteHost = remoteHost'
279− } conn restore internalError
280− throwIO e
281− where
282− internalError = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
283−
284281connSource :: Connection -> T.Handle -> Source IO ByteString
285282connSource Connection { connRecv = recv } th = src
286283 where