Skip to content

Commit b8422e8

Browse files
committed
Merge #456
2 parents fffa72b + b84016e commit b8422e8

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

doc/tutorial/Authentication.lhs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can use this combinator to protect an API as follows:
4444
4545
module Authentication where
4646
47-
import Control.Monad.Trans.Except (ExceptT, throwE)
47+
import Control.Monad.Trans.Except (ExceptT)
4848
import Data.Aeson (ToJSON)
4949
import Data.ByteString (ByteString)
5050
import Data.Map (Map, fromList)
@@ -59,6 +59,7 @@ import Servant.API ((:<|>) ((:<|>)), (:>), BasicAuth,
5959
Get, JSON)
6060
import Servant.API.BasicAuth (BasicAuthData (BasicAuthData))
6161
import Servant.API.Experimental.Auth (AuthProtect)
62+
import Servant (throwError)
6263
import Servant.Server (BasicAuthCheck (BasicAuthCheck),
6364
BasicAuthResult( Authorized
6465
, Unauthorized
@@ -173,7 +174,7 @@ And now we create the `Context` used by servant to find `BasicAuthCheck`:
173174
```haskell
174175
-- | We need to supply our handlers with the right Context. In this case,
175176
-- Basic Authentication requires a Context Entry with the 'BasicAuthCheck' value
176-
-- tagged with "foo-tag" This context is then supplied to 'server' and threaded
177+
-- tagged with "foo-tag" This context is then supplied to 'server' and threaded
177178
-- to the BasicAuth HasServer handlers.
178179
basicAuthServerContext :: Context (BasicAuthCheck User ': '[])
179180
basicAuthServerContext = authCheck :. EmptyContext
@@ -274,7 +275,7 @@ database = fromList [ ("key1", Account "Anne Briggs")
274275
-- This is our bespoke (and bad) authentication logic.
275276
lookupAccount :: ByteString -> ExceptT ServantErr IO Account
276277
lookupAccount key = case Map.lookup key database of
277-
Nothing -> throwE (err403 { errBody = "Invalid Cookie" })
278+
Nothing -> throwError (err403 { errBody = "Invalid Cookie" })
278279
Just usr -> return usr
279280
```
280281
@@ -289,7 +290,7 @@ method:
289290
authHandler :: AuthHandler Request Account
290291
authHandler =
291292
let handler req = case lookup "servant-auth-cookie" (requestHeaders req) of
292-
Nothing -> throwE (err401 { errBody = "Missing auth header" })
293+
Nothing -> throwError (err401 { errBody = "Missing auth header" })
293294
Just authCookieKey -> lookupAccount authCookieKey
294295
in mkAuthHandler handler
295296
```
@@ -329,7 +330,7 @@ We now construct the `Context` for our server, allowing us to instantiate a
329330
value of type `Server AuthGenAPI`, in addition to the server value:
330331
331332
```haskell
332-
-- | The context that will be made available to request handlers. We supply the
333+
-- | The context that will be made available to request handlers. We supply the
333334
-- "cookie-auth"-tagged request handler defined above, so that the 'HasServer' instance
334335
-- of 'AuthProtect' can extract the handler and run it on the request.
335336
genAuthServerContext :: Context (AuthHandler Request Account ': '[])

servant-docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
HEAD
2+
----
3+
4+
* Use `throwError` instead of `throwE` in documentation
5+
16
0.5
27
----
38

servant-server/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
to the correct endpoint. Functions `layout` and `layoutWithContext` have
77
been added to visualize the router layout for debugging purposes. Test
88
cases for expected router layouts have been added.
9+
* Export `throwError` from module `Servant`
910

1011
0.6.1
1112
-----

servant-server/src/Servant.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ module Servant (
1010
module Servant.Utils.StaticFiles,
1111
-- | Useful re-exports
1212
Proxy(..),
13+
throwError
1314
) where
1415

16+
import Control.Monad.Error.Class (throwError)
1517
import Data.Proxy
1618
import Servant.API
1719
import Servant.Server

0 commit comments

Comments
 (0)