Skip to content

Commit 7913a93

Browse files
authored
[servant-server] Add error 429 Too Many Requests. Fix build of examples/greet.hs (#1591)
* Fix greet.hs build * Add error 429: Too Many Requests * Add changelog entry
1 parent ca6944b commit 7913a93

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

changelog.d/1591

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
synopsis: Fix build of examples/greet.hs. Add "429 Too Many Requests" error.
2+
prs: #1591

servant-server/example/greet.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Network.Wai.Handler.Warp
1818

1919
import Servant
2020
import Servant.Server.Generic ()
21+
import Servant.API.Generic ((:-))
2122

2223
-- * Example
2324

servant-server/src/Servant/Server.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module Servant.Server
8484
, err417
8585
, err418
8686
, err422
87+
, err429
8788
-- ** 5XX
8889
, err500
8990
, err501

servant-server/src/Servant/Server/Internal/ServerError.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,20 @@ err422 = ServerError { errHTTPCode = 422
392392
, errHeaders = []
393393
}
394394

395+
-- | 'err429' Too Many Requests
396+
--
397+
-- Example:
398+
--
399+
-- > failingHandler :: Handler ()
400+
-- > failingHandler = throwError $ err429 { errBody = "You have sent too many requests in a short period of time." }
401+
--
402+
err429 :: ServerError
403+
err429 = ServerError { errHTTPCode = 429
404+
, errReasonPhrase = "Too Many Requests"
405+
, errBody = ""
406+
, errHeaders = []
407+
}
408+
395409
-- | 'err500' Internal Server Error
396410
--
397411
-- Example:

0 commit comments

Comments
 (0)