Return Reponse on functions too #347

Closed
opened 2020-05-23 13:21:24 +00:00 by ankitm123 · 7 comments

The function signature of getResponse should be changed to return the response code explicitely. Presently, it returns it inside the error message, and the end user has to parse the error to find the response code. It would be user friendly to change the signature to this:

func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, responseCode, error) {

I can work on a PR, if it is ok. For example, github and bitbucket return it separately.


this will close #303

The function signature of getResponse should be changed to return the response code explicitely. Presently, it returns it inside the error message, and the end user has to parse the error to find the response code. It would be user friendly to change the signature to this: ``` func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, responseCode, error) { ``` I can work on a PR, if it is ok. For example, github and bitbucket return it separately. --- this will close #303
Owner

if no error ocure - the expected status is recived, I think we dont need to return the status code.

But for error responce we should, so I think this is a dublicate of #303 and refactor func getResponse() is one of the results of it ...

@ankitm123 did I missed something?

if no error ocure - the expected status is recived, I think we dont need to return the status code. But for error responce we should, so I think this is a dublicate of #303 and refactor `func getResponse()` is one of the results of it ... @ankitm123 did I missed something?
Author

if no error ocure - the expected status is recived, I think we dont need to return the status code.

In that case, should it not return data,<*response>, nil? (Better to return the pointer to the response object, and let the end user work with it?). This also brings consisteny with other git providers, wdyt?

But for error responce we should, so I think this is a dublicate of #303 and refactor func getResponse() is one of the results of it ...

@ankitm123 did I missed something?

I dont think error should contain the response/status code. A separate response struct would make the code simpler imo. So something like this:

resp, err := c.doRequest(method, path, header, body)
if err != nil {
	return nil, resp, err
}
...

thoughts?

> if no error ocure - the expected status is recived, I think we dont need to return the status code. In that case, should it not return `data,<*response>, nil`? (Better to return the pointer to the response object, and let the end user work with it?). This also brings consisteny with other git providers, wdyt? > But for error responce we should, so I think this is a dublicate of #303 and refactor `func getResponse()` is one of the results of it ... > > @ankitm123 did I missed something? I dont think error should contain the response/status code. A separate response struct would make the code simpler imo. So something like this: ``` resp, err := c.doRequest(method, path, header, body) if err != nil { return nil, resp, err } ... ``` thoughts?
Owner

I would then make it similar to https://github.com/google/go-github/blob/master/github/github.go#L405

I can work on a PR, if it is ok

@ankitm123 if you like

I would then make it similar to https://github.com/google/go-github/blob/master/github/github.go#L405 > I can work on a PR, if it is ok @ankitm123 if you like
6543 changed title from Return reponse code separately for getresponse function to Return Reponse on functions 2020-05-23 15:57:35 +00:00
6543 added this to the v0.13.0 milestone 2020-05-23 15:57:39 +00:00
6543 changed title from Return Reponse on functions to Return Reponse on functions too 2020-05-23 15:58:55 +00:00
6543 added the
kind/feature
kind/breaking
labels 2020-05-23 15:59:03 +00:00
Owner

@ankitm123 what's the current status?

@ankitm123 what's the current status?
Author

I have time this week to focus on this issue, should be done by the End of Week.

I have time this week to focus on this issue, should be done by the End of Week.
Author

While going through the codebase, I came across getStatusCode function, which I think can be removed after this change. Thoughts?
May be it should be done in a separate isse, and not this?

While going through the codebase, I came across `getStatusCode` function, which I think can be removed after this change. Thoughts? May be it should be done in a separate isse, and not this?
Owner

No go on with remove it

No go on with remove it
6543 added the
has/pull
label 2020-09-12 21:12:28 +00:00
6543 closed this issue 2020-09-14 02:37:15 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/go-sdk#347
No description provided.