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

Update service_dependency.go to accept a context.Context #293

Merged
merged 1 commit into from Mar 15, 2021

Conversation

theckman
Copy link
Collaborator

This also updates the new methods to not return the *http.Response, as it
doesn't seem needed.

Updates #267

This also updates the new methods to not return the `*http.Response`, as it
doesn't seem needed.

Updates #267
@theckman theckman added this to the v1.4.0 milestone Feb 26, 2021
}

// ListBusinessServiceDependenciesWithContext lists dependencies of a business service.
func (c *Client) ListBusinessServiceDependenciesWithContext(ctx context.Context, businessServiceID string) (*ListServiceDependencies, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@stmcallister let me know what you think of these methods not including the *http.Response. As far as I can tell there isn't a need for the consumer to have the response.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe I included *http.Response so that folks could get information about the Response, status codes and messages, etc. But, it sounds like the context will provide some of this functionality?

Copy link
Collaborator Author

@theckman theckman Mar 10, 2021

Choose a reason for hiding this comment

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

@stmcallister Not the context, I think the new APIError type we created will take care of that. Since that should contain all errors in the JSON response, as well as the HTTP status code. If the call returns a nil error value, consumers should assume it's a 2xx response code. If the error value is non-nil, then they can assume it was >299 and inspect the actual error if they really want to know.

The way the *http.Response support is implemented today consumers could only get the status code and HTTP headers, but they cannot read the HTTP response body. By default the http.Response.Body can only be read once, which we do in decodeJSON. Attempts to read it again by callers would result in an io.EOF error, and so the *http.Response we return today isn't very useful, especially because there don't appear to be any documented HTTP response headers that consumers would care about.

We could fix that bug and make the *http.Response useful for consumers, but since there are no documented response headers and we handle the HTTP status code (for failures) in the APIError type, I think we should lean-away from returning the *http.Response and potentially include its removal in our breaking changes in v1.5, since the returned *http.Response never fully worked.

I'm tracking the removal here: #305

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, okay. That makes sense. Thanks for the explanation.

Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@stmcallister stmcallister merged commit 7b48aac into master Mar 15, 2021
@stmcallister stmcallister deleted the ctx_service_dependency branch March 15, 2021 23:21
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

2 participants