Skip to content

Commit c7de0c7

Browse files
committed
submitRequest: raise new RequestTooLargeException on HTTP 413 responses
1 parent ad37a58 commit c7de0c7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Network/Mattermost/Connection.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ doUnauthRequest cd = submitRequest cd Nothing
102102
-- raises 'RateLimitException' with the fields populated from the
103103
-- response headers where possible.
104104
--
105+
-- If the request fails due to a 413 (too-large) response, this raises
106+
-- 'RequestTooLargeException'.
107+
--
105108
-- If the response status is 2XX, the response is returned.
106109
--
107110
-- If the response status is anything else, its body is assumed to be
@@ -165,6 +168,9 @@ submitRequest cd mToken method uri payload = do
165168

166169
rsp <- hoistE (left ConnectionException rawResponse)
167170
case HTTP.rspCode rsp of
171+
(4, 1, 3) ->
172+
throwIO RequestTooLargeException
173+
168174
(4, 2, 9) -> do
169175
-- Extract rate limit information if possible
170176
let headers = HTTP.getHeaders rsp

src/Network/Mattermost/Exceptions.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Network.Mattermost.Exceptions
1313
, ConnectionException(..)
1414
, MattermostServerError(..)
1515
, RateLimitException(..)
16+
, RequestTooLargeException(..)
1617
) where
1718

1819
import qualified Data.Aeson as A
@@ -86,6 +87,13 @@ data MattermostServerError = MattermostServerError T.Text
8687

8788
instance Exception MattermostServerError
8889

90+
-- | An exception raised when a request's size was too large for the
91+
-- server and was thus rejected.
92+
data RequestTooLargeException = RequestTooLargeException
93+
deriving (Eq, Show)
94+
95+
instance Exception RequestTooLargeException
96+
8997
-- | An exception raised when a request could not be completed due to a
9098
-- request rate limit violation.
9199
data RateLimitException =

0 commit comments

Comments
 (0)