From f484483d8455ecb38c1a64e999e875a024dca937 Mon Sep 17 00:00:00 2001 From: Luke Cycon Date: Fri, 8 Apr 2016 12:06:44 -0700 Subject: [PATCH 1/3] Re-export `throwE` from module `Servant` Fixes #442 --- servant-server/src/Servant.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/servant-server/src/Servant.hs b/servant-server/src/Servant.hs index 96fd219f..ed24756d 100644 --- a/servant-server/src/Servant.hs +++ b/servant-server/src/Servant.hs @@ -10,8 +10,10 @@ module Servant ( module Servant.Utils.StaticFiles, -- | Useful re-exports Proxy(..), + throwError ) where +import Control.Monad.Error.Class (throwError) import Data.Proxy import Servant.API import Servant.Server From 353c1798e10284f8a682151c1e584705abbf66e1 Mon Sep 17 00:00:00 2001 From: Luke Cycon Date: Mon, 11 Apr 2016 11:19:18 -0700 Subject: [PATCH 2/3] Update some docs and the changelogs --- doc/tutorial/Authentication.lhs | 11 ++++++----- servant-docs/CHANGELOG.md | 5 +++++ servant-server/CHANGELOG.md | 5 +++++ servant/CHANGELOG.md | 5 +++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/tutorial/Authentication.lhs b/doc/tutorial/Authentication.lhs index b9117e55..b699b46a 100644 --- a/doc/tutorial/Authentication.lhs +++ b/doc/tutorial/Authentication.lhs @@ -44,7 +44,7 @@ You can use this combinator to protect an API as follows: module Authentication where -import Control.Monad.Trans.Except (ExceptT, throwE) +import Control.Monad.Trans.Except (ExceptT) import Data.Aeson (ToJSON) import Data.ByteString (ByteString) import Data.Map (Map, fromList) @@ -59,6 +59,7 @@ import Servant.API ((:<|>) ((:<|>)), (:>), BasicAuth, Get, JSON) import Servant.API.BasicAuth (BasicAuthData (BasicAuthData)) import Servant.API.Experimental.Auth (AuthProtect) +import Servant (throwError) import Servant.Server (BasicAuthCheck (BasicAuthCheck), BasicAuthResult( Authorized , Unauthorized @@ -173,7 +174,7 @@ And now we create the `Context` used by servant to find `BasicAuthCheck`: ```haskell -- | We need to supply our handlers with the right Context. In this case, -- Basic Authentication requires a Context Entry with the 'BasicAuthCheck' value --- tagged with "foo-tag" This context is then supplied to 'server' and threaded +-- tagged with "foo-tag" This context is then supplied to 'server' and threaded -- to the BasicAuth HasServer handlers. basicAuthServerContext :: Context (BasicAuthCheck User ': '[]) basicAuthServerContext = authCheck :. EmptyContext @@ -274,7 +275,7 @@ database = fromList [ ("key1", Account "Anne Briggs") -- This is our bespoke (and bad) authentication logic. lookupAccount :: ByteString -> ExceptT ServantErr IO Account lookupAccount key = case Map.lookup key database of - Nothing -> throwE (err403 { errBody = "Invalid Cookie" }) + Nothing -> throwError (err403 { errBody = "Invalid Cookie" }) Just usr -> return usr ``` @@ -289,7 +290,7 @@ method: authHandler :: AuthHandler Request Account authHandler = let handler req = case lookup "servant-auth-cookie" (requestHeaders req) of - Nothing -> throwE (err401 { errBody = "Missing auth header" }) + Nothing -> throwError (err401 { errBody = "Missing auth header" }) Just authCookieKey -> lookupAccount authCookieKey in mkAuthHandler handler ``` @@ -329,7 +330,7 @@ We now construct the `Context` for our server, allowing us to instantiate a value of type `Server AuthGenAPI`, in addition to the server value: ```haskell --- | The context that will be made available to request handlers. We supply the +-- | The context that will be made available to request handlers. We supply the -- "cookie-auth"-tagged request handler defined above, so that the 'HasServer' instance -- of 'AuthProtect' can extract the handler and run it on the request. genAuthServerContext :: Context (AuthHandler Request Account ': '[]) diff --git a/servant-docs/CHANGELOG.md b/servant-docs/CHANGELOG.md index 44ce0696..555fb8b1 100644 --- a/servant-docs/CHANGELOG.md +++ b/servant-docs/CHANGELOG.md @@ -1,3 +1,8 @@ +HEAD +---- + +* Export `throwError` from module `Servant` + 0.5 ---- diff --git a/servant-server/CHANGELOG.md b/servant-server/CHANGELOG.md index 8b1c25e2..64498f6a 100644 --- a/servant-server/CHANGELOG.md +++ b/servant-server/CHANGELOG.md @@ -1,3 +1,8 @@ +HEAD +---- + +* Export `throwError` from module `Servant` + 0.6 --- diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index efeecf66..fc147054 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -1,3 +1,8 @@ +HEAD +---- + +* Export `throwError` from module `Servant` + 0.5 ---- From b84016e19101683d8dfa641e43ece5110a6612a6 Mon Sep 17 00:00:00 2001 From: Luke Cycon Date: Mon, 11 Apr 2016 21:54:04 -0700 Subject: [PATCH 3/3] Sort out this changelog situation --- servant-docs/CHANGELOG.md | 2 +- servant/CHANGELOG.md | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/servant-docs/CHANGELOG.md b/servant-docs/CHANGELOG.md index 555fb8b1..3fed9973 100644 --- a/servant-docs/CHANGELOG.md +++ b/servant-docs/CHANGELOG.md @@ -1,7 +1,7 @@ HEAD ---- -* Export `throwError` from module `Servant` +* Use `throwError` instead of `throwE` in documentation 0.5 ---- diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index fc147054..efeecf66 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -1,8 +1,3 @@ -HEAD ----- - -* Export `throwError` from module `Servant` - 0.5 ----