newResponse converts an *http.Response to *Response
(httpResponse *http.Response)
| 106 | |
| 107 | // newResponse converts an *http.Response to *Response |
| 108 | func (client *Client) newResponse(httpResponse *http.Response) (*Response, error) { |
| 109 | if httpResponse == nil { |
| 110 | return nil, fmt.Errorf("%T cannot be nil", httpResponse) |
| 111 | } |
| 112 | |
| 113 | resp := new(Response) |
| 114 | resp.HTTPResponse = httpResponse |
| 115 | |
| 116 | buf, err := io.ReadAll(resp.HTTPResponse.Body) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | resp.Body = &buf |
| 121 | |
| 122 | return resp, resp.Error() |
| 123 | } |