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