-
-
Notifications
You must be signed in to change notification settings - Fork 416
Derive HasClient good response status from Verb status #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derive HasClient good response status from Verb status #1469
Conversation
548a80b
to
3c6a2b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great thanks, and sorry for the delay!
Do you perhaps feel like adding a test case where the server returns e.g 201 but the client wants 200, to make sure this doesn't break in the future?
@tchoutri I suspect we'll want to be very loud and clear about this when announcing the release that ships this, including in the changelog. This might even upset some users ("but the response is a 2xx, it should be fine!"), perhaps? I don't know.
You got it boss |
3c6a2b5
to
50bc905
Compare
@@ -83,6 +83,9 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do | |||
let p = Person "Clara" 42 | |||
left show <$> runClient (getBody p) baseUrl `shouldReturn` Right p | |||
|
|||
it "Servant.API.Get redirection" $ \(_, baseUrl) -> do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of this test being that before your patch, we'd get a ClientError
because we don't get a 2xx status code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea. I also checked the same test in master
and it returns, as expected, a FailureResponse
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, this is similar to the "Redirects when appropriate"
test, that uses uverbGetSuccessOrRedirect True
, but for Verb
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sounds good. Since it wasn't 100% obvious to me initially, that might be the case for other contributors, perhaps indicating the purpose in the test label or a comment nearby would help. But the test otherwise looks good.
I had a look at how to add this test, and I was not sure how to proceed. type ServerAPI = Verb GET 201 '[JSON] ()
type ClientAPI = Verb GET 200 '[JSON] () I tried to use also the free monad client in the |
For testing this precise thing, I'd do exactly what you said, no need to appeal to the big common API type with a bunch of constructs in it. Just the two tiny almost-identical, differing-only-in-status-code endpoint types you gave seem perfect. They're even short enough to write them inline, |
I added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Hi Everyone,
There's a limitation/bug in the
HasClient
instances for theVerb
datatype.If I try to perform a client request with
runClientM
, I'll obtain a successful response if and only if the backend endpoint returns a response with status code >=200 and <300. This is due to the use ofrunRequest
in theclientWithRoute
definitions.This PR brings the following changes:
runRequest
withrunRequestAcceptStatus
in theVerb
instances for theHasClient
class (as suggested by @alpmestan).Verb
status.statusIsSuccessful
fromNetwork.HTTP.Types.Status
to lighten the code (not required to solve the issue).