diff --git a/changelog.d/1591 b/changelog.d/1591 new file mode 100644 index 000000000..a9abd79b6 --- /dev/null +++ b/changelog.d/1591 @@ -0,0 +1,2 @@ +synopsis: Fix build of examples/greet.hs. Add "429 Too Many Requests" error. +prs: #1591 diff --git a/servant-server/example/greet.hs b/servant-server/example/greet.hs index 0b994cd36..606b9951d 100644 --- a/servant-server/example/greet.hs +++ b/servant-server/example/greet.hs @@ -18,6 +18,7 @@ import Network.Wai.Handler.Warp import Servant import Servant.Server.Generic () +import Servant.API.Generic ((:-)) -- * Example diff --git a/servant-server/src/Servant/Server.hs b/servant-server/src/Servant/Server.hs index 79d092b95..07d5fb912 100644 --- a/servant-server/src/Servant/Server.hs +++ b/servant-server/src/Servant/Server.hs @@ -84,6 +84,7 @@ module Servant.Server , err417 , err418 , err422 + , err429 -- ** 5XX , err500 , err501 diff --git a/servant-server/src/Servant/Server/Internal/ServerError.hs b/servant-server/src/Servant/Server/Internal/ServerError.hs index 5b5d56e2a..650f6e10d 100644 --- a/servant-server/src/Servant/Server/Internal/ServerError.hs +++ b/servant-server/src/Servant/Server/Internal/ServerError.hs @@ -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: