Skip to content

Commit a70fb68

Browse files
authored
version 0.1.2.2: ignore ConnectionClosedByPeer exc (#15)
1 parent 4dd73fb commit a70fb68

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.1.2.2] - 2020-05-19
10+
### Changed
11+
- Ignore `"Warp: Client closed connection prematurely"` exception.
12+
913
## [0.1.2.1] - 2020-04-15
1014
### Added
1115
- `runWebServerWith` function that runs a web server with custom Warp settings.

src/Web/Template/Server.hs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module Web.Template.Server
1414
) where
1515

1616
import Control.Concurrent (threadDelay)
17-
import Control.Exception (AsyncException (..),
18-
SomeException (..), catch,
17+
import Control.Exception (AsyncException (..), SomeException (..), catch,
1918
fromException)
2019
import Control.Monad (unless)
2120
import Control.Monad.RWS (RWST, evalRWST)
@@ -24,18 +23,16 @@ import Data.Text.Encoding (encodeUtf8)
2423
import Data.Text.Lazy as TL (Text, toStrict)
2524
import Network.HTTP.Types.Header (Header)
2625
import 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)
3331
import System.BCD.Log (error')
3432
import 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)
3936
import Web.Template.Except (Except, JsonWebError (..), handleEx)
4037
import Web.Template.Log (bcdlog)
4138
import Web.Template.Types
@@ -115,7 +112,12 @@ scottyOpts port userSettings = Options 1 warpSettings
115112
$ defaultSettings
116113

117114
onException :: 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

120122
auth :: Monoid w => Process r w s -> WebM r w s ()
121123
auth (Process p) = p

web-template.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: web-template
2-
version: 0.1.2.1
2+
version: 0.1.2.2
33
synopsis: Web template
44
description:
55
Web template includes:

0 commit comments

Comments
 (0)