diff --git a/client/client.go b/client/client.go index 668a35d..bda08ba 100644 --- a/client/client.go +++ b/client/client.go @@ -116,11 +116,6 @@ func (n *portainerClientImp) do(uri, method string, requestBody io.Reader, heade } } - err = checkResponseForErrors(resp) - if err != nil { - return - } - return } @@ -160,6 +155,11 @@ func (n *portainerClientImp) doJSON(uri, method string, headers http.Header, req return err } + err = checkResponseForErrors(resp) + if err != nil { + return err + } + // Decode response body, if any if responseBody != nil { d := json.NewDecoder(resp.Body) diff --git a/client/client_test.go b/client/client_test.go index c69af0c..5542f1f 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -105,15 +105,6 @@ func Test_portainerClientImp_do(t *testing.T) { }, wantErr: true, }, - { - name: "returns error on response error", - fields: fields{ - server: httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - w.WriteHeader(http.StatusInternalServerError) - })), - }, - wantErr: true, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -229,6 +220,20 @@ func Test_portainerClientImp_doJSON(t *testing.T) { wantRespBody: map[string]interface{}{}, wantErr: true, }, + { + name: "returns error on response error", + fields: fields{ + server: httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + w.WriteHeader(http.StatusInternalServerError) + })), + }, + args: args{ + uri: "stacks", + method: http.MethodPost, + headers: http.Header{}, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {