@@ -14,8 +14,7 @@ module Web.Template.Server
1414 ) where
1515
1616import Control.Concurrent (threadDelay )
17- import Control.Exception (AsyncException (.. ),
18- SomeException (.. ), catch ,
17+ import Control.Exception (AsyncException (.. ), SomeException (.. ), catch ,
1918 fromException )
2019import Control.Monad (unless )
2120import Control.Monad.RWS (RWST , evalRWST )
@@ -24,18 +23,16 @@ import Data.Text.Encoding (encodeUtf8)
2423import Data.Text.Lazy as TL (Text , toStrict )
2524import Network.HTTP.Types.Header (Header )
2625import Network.HTTP.Types.Status (status401 )
27- import Network.Wai (Application , Middleware , Request ,
28- mapResponseHeaders , modifyResponse )
29- import Network.Wai.Handler.Warp (Settings , defaultSettings ,
30- exceptionResponseForDebug ,
31- setOnException ,
26+ import Network.Wai (Application , Middleware , Request , mapResponseHeaders ,
27+ modifyResponse )
28+ import Network.Wai.Handler.Warp (InvalidRequest (.. ), Settings , defaultSettings ,
29+ exceptionResponseForDebug , setOnException ,
3230 setOnExceptionResponse , setPort )
3331import System.BCD.Log (error' )
3432import Web.Cookie (parseCookiesText )
35- import Web.Scotty.Trans (Options (.. ), ScottyT ,
36- defaultHandler , header , json ,
37- middleware , next , param , scottyAppT ,
38- scottyOptsT , status )
33+ import Web.Scotty.Trans (Options (.. ), ScottyT , defaultHandler , header , json ,
34+ middleware , next , param , scottyAppT , scottyOptsT ,
35+ status )
3936import Web.Template.Except (Except , JsonWebError (.. ), handleEx )
4037import Web.Template.Log (bcdlog )
4138import Web.Template.Types
@@ -115,7 +112,12 @@ scottyOpts port userSettings = Options 1 warpSettings
115112 $ defaultSettings
116113
117114onException :: Maybe Request -> SomeException -> IO ()
118- onException _ e = error' (" scotty" :: Text ) $ show e
115+ onException _ e =
116+ case fromException e of
117+ -- This exception happens too often when using Chrome, thus we better ignore it.
118+ -- See https://github.com/yesodweb/wai/issues/421
119+ Just ConnectionClosedByPeer -> return ()
120+ _ -> error' (" scotty" :: Text ) $ show e
119121
120122auth :: Monoid w => Process r w s -> WebM r w s ()
121123auth (Process p) = p
0 commit comments