Skip to content
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

Add response code to common http_client #52

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ranoble
Copy link

@ranoble ranoble commented Feb 15, 2021

This PR modified the HTTP client so that:

  • It returns the HTTP code for the request
  • If the response body exists, it is returned. If the request itself failed, no response is returned.

This means that we can act on a failed response, and that context is not lost.

…s, and the inclusion of the request allows us to act according to requests that couldn't be sent, and ones that we're sent, and an attempt made at handling them, but failed.
common/util.go Outdated Show resolved Hide resolved
@RealHarshThakur
Copy link
Member

Thanks for the PR @ranoble . We'll merge this and then we can follow it up with a PR where other packages use the latest git commit of it

common/util.go Outdated
}
return resp, nil
return &resp.StatusCode, resp, nil
Copy link
Contributor

@therahulbhati therahulbhati Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I would like to understand the reason why we are returning status code if it can be extracted from response.

Copy link
Member

@RealHarshThakur RealHarshThakur Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we should have status code, response body(instead of whole response) and error . If we look at how connectors are using it, it made sense to me if we do it that way. What are your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should utilize status code, but the same status code can be read from the response that way it's more pragmatic and avoid duplication. Think of this package as an HTTP package which only returns response and error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be duplicate if we have status code , body and error as paramaters, right?

Copy link
Author

@ranoble ranoble Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core reason for this change was to allow an error handler to read the response headers, not just the body in the case of an error. This is initially to support keys for kafka in error topics - so that we can control partitioning and compaction.

We have 3 states:

  • Request could not. be sent (network down etc)
  • Request sent, but responded with an error - in this case with the current setup we get a nil for response.
  • Success.

If we move to 'body' only, we'll lose a chance to handle partitioning and compaction or any of the more advanced features of kafka (at least for errors).

Copy link
Member

@RealHarshThakur RealHarshThakur Feb 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranoble So do you suggest we should read the status code from the response object itself? That's the point of the PR though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the initial proposal. The concern was that you'd have both a response AND an error.
I don't really see this as a problem (but then I'm not a golang native, so I'd follow your guidance), as you can safely ignore the response if you don't need it, but use it if you do (in the kafka case).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also backwards compatible - and I always prefer that...

Copy link
Contributor

@therahulbhati therahulbhati Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranoble From the code changes you made, it seems you have introduced the following changes:

  1. Returning status code from function
  2. At line no. 97 you are returning resp instead of nil if resp.StatusCode < 200 || resp.StatusCode > 300

The second change makes sense as we would have more info about errors which can be utilized while writing to error topic/queue. I don't think the first change is necessary as we can get the status code from response directly.

@RealHarshThakur
Copy link
Member

@vishal-biyani I am wondering given the dependency issue other packages seem to be running into for such a small piece of code, would it best if each connector had it's own implementation? In a way, only the aws connectors require the common package. Others connectors can have the same piece of code.

@vishal-biyani
Copy link
Member

@RealHarshThakur That works - what is change needed in this PR - or we need another set of PR for this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants