mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Move response errors checking from portainerClientImp.do() to doJSON()
This commit is contained in:
parent
be6aa497d8
commit
16517713ac
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user