Skip to content

Commit

Permalink
[servant-server] Add error 429 Too Many Requests. Fix build of exampl…
Browse files Browse the repository at this point in the history
…es/greet.hs (#1591)

* Fix greet.hs build

* Add error 429: Too Many Requests

* Add changelog entry
  • Loading branch information
Daniel-Diaz committed Sep 11, 2023
1 parent ca6944b commit 7913a93
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.d/1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
synopsis: Fix build of examples/greet.hs. Add "429 Too Many Requests" error.
prs: #1591
1 change: 1 addition & 0 deletions servant-server/example/greet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Network.Wai.Handler.Warp

import Servant
import Servant.Server.Generic ()
import Servant.API.Generic ((:-))

-- * Example

Expand Down
1 change: 1 addition & 0 deletions servant-server/src/Servant/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module Servant.Server
, err417
, err418
, err422
, err429
-- ** 5XX
, err500
, err501
Expand Down
14 changes: 14 additions & 0 deletions servant-server/src/Servant/Server/Internal/ServerError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,20 @@ err422 = ServerError { errHTTPCode = 422
, errHeaders = []
}

-- | 'err429' Too Many Requests
--
-- Example:
--
-- > failingHandler :: Handler ()
-- > failingHandler = throwError $ err429 { errBody = "You have sent too many requests in a short period of time." }
--
err429 :: ServerError
err429 = ServerError { errHTTPCode = 429
, errReasonPhrase = "Too Many Requests"
, errBody = ""
, errHeaders = []
}

-- | 'err500' Internal Server Error
--
-- Example:
Expand Down

0 comments on commit 7913a93

Please sign in to comment.