I want to extract the body of the gitea.Response , however it appears closed
"read on closed response body error"
For example:
data, gitResp, err := client.MigrateRepo(opts)
Receive an 409 Conflict but was unable to get the message of why it failed
If i use the REST endpoints I get a response
{
"message": "The repository with the same name already exists.",
"url": "http://gitea-http:3000/api/swagger"
}
Figured i could read the response body i would get that info
Any insight on? Thanks
I want to extract the body of the gitea.Response , however it appears closed
"read on closed response body error"
For example:
1. `data, gitResp, err := client.MigrateRepo(opts)`
2. Receive an 409 Conflict but was unable to get the message of why it failed
3. If i use the REST endpoints I get a response
```
{
"message": "The repository with the same name already exists.",
"url": "http://gitea-http:3000/api/swagger"
}
```
4. Figured i could read the response body i would get that info
Any insight on? Thanks
As you can see on the statusCodeToErr , if an err as occurred then the data contains the details of that error
I changed the code on my local and able to get the error cause ... rather than the "conflict"
1. On the client.go file applied a small change on func getResponse
```
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, *Response, error) {
resp, err := c.doRequest(method, path, header, body)
if err != nil {
return nil, nil, err
}
defer resp.Body.Close()
// check for errors
data, err := statusCodeToErr(resp)
if err != nil {
return data, resp, errors.New(string(data))
}
```
2. As you can see on the statusCodeToErr , if an err as occurred then the data contains the details of that error
if you provide a http.Response then the caller assumes they also have the resp.body. so it should be exposed
the other alternative not provide the http.Response ( sdk has abstracted that away ). so now the caller is only provided the data and error
for example:
data, err := client.MigrateRepo(opts)
two choices (imho)
1. if you provide a http.Response then the caller assumes they also have the resp.body. so it should be exposed
2. the other alternative not provide the http.Response ( sdk has abstracted that away ). so now the caller is only provided the data and error
for example:
data, err := client.MigrateRepo(opts)
I want to extract the body of the gitea.Response , however it appears closed
"read on closed response body error"
For example:
data, gitResp, err := client.MigrateRepo(opts)
Receive an 409 Conflict but was unable to get the message of why it failed
If i use the REST endpoints I get a response
Any insight on? Thanks
I changed the code on my local and able to get the error cause ... rather than the "conflict"
The
resp.body
has been consumed in internal. Should we expose that?two choices (imho)
if you provide a http.Response then the caller assumes they also have the resp.body. so it should be exposed
the other alternative not provide the http.Response ( sdk has abstracted that away ). so now the caller is only provided the data and error
for example:
data, err := client.MigrateRepo(opts)
I like the first one.