@@ -24,9 +24,9 @@ type Connection interface {
2424 // Builds a http.Request and setup up headers. The body can provided as io.Reader
2525 BuildRequestRaw (verb string , path string , body io.Reader ) (* http.Request , error )
2626
27- // Performs an HTTP request to the remote API. Returns the response body or
28- // an error object.
29- Do (* http.Request ) ([]byte , error )
27+ // Performs an HTTP request to the remote API. Returns the status code and
28+ // the response body, or an error object.
29+ Do (* http.Request ) (int , []byte , error )
3030
3131 // Returns the credentials object to be used for authenticated requests.
3232 GetCredentials () Credentials
@@ -77,35 +77,35 @@ func (conn ApiConnection) BuildRequestRaw(verb string, path string, body io.Read
7777 return request , nil
7878}
7979
80- func (conn ApiConnection ) Do (request * http.Request ) ([]byte , error ) {
80+ func (conn ApiConnection ) Do (request * http.Request ) (int , []byte , error ) {
8181 token , tokenErr := conn .Credentials .Token ()
8282 if tokenErr != nil {
83- return []byte {}, tokenErr
83+ return 0 , []byte {}, tokenErr
8484 }
8585 request .Header .Set ("System-Token" , token )
8686
8787 response , doErr := conn .setupHTTPClient ().Do (request )
8888 if doErr != nil {
89- return nil , doErr
89+ return 0 , nil , doErr
9090 }
9191 defer response .Body .Close ()
9292
9393 // Update the credentials from the new system token.
9494 token = response .Header .Get ("System-Token" )
9595 if err := conn .Credentials .UpdateToken (token ); err != nil {
96- return nil , err
96+ return 0 , nil , err
9797 }
9898
9999 // Check if there was an error from the given API response.
100100 if apiError := ErrorFromResponse (response ); apiError != nil {
101- return nil , apiError
101+ return 0 , nil , apiError
102102 }
103103
104104 data , readErr := io .ReadAll (response .Body )
105105 if readErr != nil {
106- return nil , readErr
106+ return 0 , nil , readErr
107107 }
108- return data , nil
108+ return response . StatusCode , data , nil
109109}
110110
111111func (conn ApiConnection ) GetCredentials () Credentials {
0 commit comments