Skip to content

Commit

Permalink
Simplified ErrorResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Théophile Choutri committed Aug 28, 2024
1 parent a3f8ef7 commit a61130b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions servant-client/test/Servant/ClientTestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ type GetUserMultiVerb =
(Either UserNotFound Person)

type GetUserMultiVerbResponses =
[ErrorResponse UserNotFound, RespondAs JSON 200 "Person" Person]
[ErrorResponse UserNotFound, Respond 200 "User found" Person]

instance (res ~ GetUserMultiVerbResponses) => AsUnion res (Either UserNotFound Person) where
toUnion = eitherToUnion (toUnion @_) (Z . I)
fromUnion = eitherFromUnion (fromUnion @_) (unI . unZ)
toUnion = eitherToUnion (toUnion @'[ErrorResponse UserNotFound]) (Z . I)
fromUnion = eitherFromUnion (fromUnion @'[ErrorResponse UserNotFound]) (unI . unZ)

type Api =
Get '[JSON] Person
Expand Down Expand Up @@ -212,8 +212,8 @@ type Api =
WithStatus 301 Text]
:<|> "uverb-get-created" :> UVerb 'GET '[PlainText] '[WithStatus 201 Person]
:<|> NamedRoutes RecordRoutes
:<|> "captureVerbatim" :> Capture "someString" Verbatim :> Get '[PlainText] Text
:<|> GetUserMultiVerb
:<|> "captureVerbatim" :> Capture "someString" Verbatim :> Get '[PlainText] Text

api :: Proxy Api
api = Proxy
Expand Down Expand Up @@ -247,8 +247,8 @@ uverbGetSuccessOrRedirect :: Bool
WithStatus 301 Text])
uverbGetCreated :: ClientM (Union '[WithStatus 201 Person])
recordRoutes :: RecordRoutes (AsClientT ClientM)
getUserMultiVerb :: Int -> ClientM (Either UserNotFound Person)
captureVerbatim :: Verbatim -> ClientM Text
getUserMultiVerb :: Int -> ClientM (Maybe Person)

getRoot
:<|> getGet
Expand Down Expand Up @@ -277,8 +277,8 @@ getRoot
:<|> uverbGetSuccessOrRedirect
:<|> uverbGetCreated
:<|> recordRoutes
:<|> captureVerbatim
:<|> getUserMultiVerb = client api
:<|> getUserMultiVerb
:<|> captureVerbatim = client api

server :: Application
server = serve api (
Expand Down Expand Up @@ -332,8 +332,8 @@ server = serve api (
{ something = pure ["foo", "bar", "pweet"]
}
}
:<|> pure $ Right $ Person "Name" 30
:<|> pure . decodeUtf8 . unVerbatim
:<|> undefined --pure $ Just $ Person "Name" 30
)

-- * api for testing failures
Expand Down

0 comments on commit a61130b

Please sign in to comment.