Fixes for ServantErr in servant-client
This commit is contained in:
parent
45f8c2c458
commit
1447221a16
3 changed files with 15 additions and 16 deletions
|
@ -37,8 +37,6 @@ import Network.HTTP.Media
|
|||
import qualified Network.HTTP.Types as H
|
||||
import qualified Network.HTTP.Types.Header as HTTP
|
||||
import Servant.API
|
||||
import Servant.API.ResponseHeaders
|
||||
import Servant.API.ContentTypes
|
||||
import Servant.Common.BaseUrl
|
||||
import Servant.Common.Req
|
||||
|
||||
|
|
|
@ -108,15 +108,14 @@ server = serve api (
|
|||
:<|> return
|
||||
:<|> (\ name -> case name of
|
||||
Just "alice" -> return alice
|
||||
Just name -> left (400, name ++ " not found")
|
||||
|
||||
Nothing -> left (400, "missing parameter"))
|
||||
Just name -> left $ ServantErr 400 (name ++ " not found") "" []
|
||||
Nothing -> left $ ServantErr 400 "missing parameter" "" [])
|
||||
:<|> (\ names -> return (zipWith Person names [0..]))
|
||||
:<|> return
|
||||
:<|> (\ name -> case name of
|
||||
Just "alice" -> return alice
|
||||
Just name -> left (400, name ++ " not found")
|
||||
Nothing -> left (400, "missing parameter"))
|
||||
Just name -> left $ ServantErr 400 (name ++ " not found") "" []
|
||||
Nothing -> left $ ServantErr 400 "missing parameter" "" [])
|
||||
:<|> (\ names -> return (zipWith Person names [0..]))
|
||||
:<|> return
|
||||
:<|> (\ _request respond -> respond $ responseLBS ok200 [] "rawSuccess")
|
||||
|
@ -262,7 +261,7 @@ spec = do
|
|||
let test :: (WrappedApi, String) -> Spec
|
||||
test (WrappedApi api, desc) =
|
||||
it desc $
|
||||
withWaiDaemon (return (serve api (left (500, "error message")))) $
|
||||
withWaiDaemon (return (serve api (left $ ServantErr 500 "error message" "" []))) $
|
||||
\ host -> do
|
||||
let getResponse :: BaseUrl -> EitherT ServantError IO ()
|
||||
getResponse = client api
|
||||
|
@ -308,7 +307,7 @@ spec = do
|
|||
_ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
|
||||
|
||||
data WrappedApi where
|
||||
WrappedApi :: (HasServer (Canonicalize api), Server api ~ EitherT (Int, String) IO a,
|
||||
WrappedApi :: (HasServer (Canonicalize api), Server api ~ EitherT ServantErr IO a,
|
||||
HasClient (Canonicalize api), Client api ~ (BaseUrl -> EitherT ServantError IO ())) =>
|
||||
Proxy api -> WrappedApi
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
module Servant.API (
|
||||
|
||||
|
@ -61,14 +61,14 @@ module Servant.API (
|
|||
import Data.Proxy (Proxy (..))
|
||||
import Servant.API.Alternative ((:<|>) (..))
|
||||
import Servant.API.Capture (Capture)
|
||||
import Servant.API.ContentTypes (Accept(..), FormUrlEncoded,
|
||||
import Servant.API.ContentTypes (Accept (..), FormUrlEncoded,
|
||||
FromFormUrlEncoded (..), JSON,
|
||||
MimeRender (..),
|
||||
MimeUnrender (..), OctetStream,
|
||||
PlainText, ToFormUrlEncoded (..))
|
||||
import Servant.API.Delete (Delete)
|
||||
import Servant.API.Get (Get)
|
||||
import Servant.API.Header (Header(..))
|
||||
import Servant.API.Header (Header (..))
|
||||
import Servant.API.MatrixParam (MatrixFlag, MatrixParam,
|
||||
MatrixParams)
|
||||
import Servant.API.Patch (Patch)
|
||||
|
@ -78,9 +78,11 @@ import Servant.API.QueryParam (QueryFlag, QueryParam,
|
|||
QueryParams)
|
||||
import Servant.API.Raw (Raw)
|
||||
import Servant.API.ReqBody (ReqBody)
|
||||
import Servant.API.ResponseHeaders (Headers, getHeaders,
|
||||
getHeadersHList, getResponse,
|
||||
buildHeadersTo, addHeader)
|
||||
import Servant.API.ResponseHeaders (AddHeader (addHeader),
|
||||
BuildHeadersTo (buildHeadersTo),
|
||||
GetHeaders (getHeaders),
|
||||
HList (..), Headers (..),
|
||||
getHeadersHList, getResponse)
|
||||
import Servant.API.Sub ((:>))
|
||||
import Servant.Common.Text (FromText (..), ToText (..))
|
||||
import Servant.Utils.Links (HasLink (..), IsElem, IsElem',
|
||||
|
|
Loading…
Reference in a new issue