@@ -102,8 +102,8 @@ defaultSettings :: Settings
102defaultSettings = Settings
102defaultSettings = Settings
103 { settingsPort = 3000
103 { settingsPort = 3000
104 , settingsHost = "*4"
104 , settingsHost = "*4"
105− , settingsOnException = defaultExceptionHandler
105+ , settingsOnException = defaultOnException
106− , settingsOnExceptionResponse = defaultExceptionResponse
106+ , settingsOnExceptionResponse = defaultOnExceptionResponse
107 , settingsOnOpen = const $ return True
107 , settingsOnOpen = const $ return True
108 , settingsOnClose = const $ return ()
108 , settingsOnClose = const $ return ()
109 , settingsTimeout = 30
109 , settingsTimeout = 30
@@ -118,7 +118,7 @@ defaultSettings = Settings
118 , settingsProxyProtocol = ProxyProtocolNone
118 , settingsProxyProtocol = ProxyProtocolNone
121−-- | Apply the logic provided by 'defaultExceptionHandler' to determine if an
121+-- | Apply the logic provided by 'defaultOnException' to determine if an
122-- exception should be shown or not. The goal is to hide exceptions which occur
122-- exception should be shown or not. The goal is to hide exceptions which occur
123-- under the normal course of the web server running.
123-- under the normal course of the web server running.
@@ -132,15 +132,21 @@ defaultShouldDisplayException se
132 | Just TimeoutThread <- fromException se = False
132 | Just TimeoutThread <- fromException se = False
133 | otherwise = True
133 | otherwise = True
135+-- | Printing an exception to standard error
136+-- if `defaultShouldDisplayException` returns `True`.
135−defaultExceptionHandler :: Maybe Request -> SomeException -> IO ()
137+defaultOnException :: Maybe Request -> SomeException -> IO ()
136−defaultExceptionHandler _ e =
138+defaultOnException _ e =
137 when (defaultShouldDisplayException e)
139 when (defaultShouldDisplayException e)
138 $ TIO.hPutStrLn stderr $ T.pack $ show e
140 $ TIO.hPutStrLn stderr $ T.pack $ show e
142+-- | Sending 400 for bad requests. Sending 500 for internal server errors.
140−defaultExceptionResponse :: SomeException -> Response
143+defaultOnExceptionResponse :: SomeException -> Response
144+defaultOnExceptionResponse e
145+ | Just (_ :: InvalidRequest) <- fromException e = responseLBS H.badRequest400 [(H.hContentType, "text/plain; charset=utf-8")] "Bad Request"
141−defaultExceptionResponse _ = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] "Something went wrong"
146+ | otherwise = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] "Something went wrong"
143−-- | Default implementation of 'settingsOnExceptionResponse' for the debugging purpose. 500, text/plain, a showed exception.
148+-- | Default implementation of 'settingsOnExceptionResponse'
149+-- for the debugging purpose. 500, text/plain, a showed exception.
144exceptionResponseForDebug :: SomeException -> Response
150exceptionResponseForDebug :: SomeException -> Response
145exceptionResponseForDebug e = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] (TLE.encodeUtf8 $ TL.pack $ "Exception: " ++ show e)
151exceptionResponseForDebug e = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] (TLE.encodeUtf8 $ TL.pack $ "Exception: " ++ show e)