mirror of https://github.com/portainer/portainer
fix(api): fix a panic issue when retrieving Docker API response
parent
3b14e6b6b9
commit
7754933470
|
@ -13,6 +13,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// ErrEmptyResponseBody defines an error raised when portainer excepts to parse the body of a HTTP response and there is nothing to parse
|
// ErrEmptyResponseBody defines an error raised when portainer excepts to parse the body of a HTTP response and there is nothing to parse
|
||||||
ErrEmptyResponseBody = portainer.Error("Empty response body")
|
ErrEmptyResponseBody = portainer.Error("Empty response body")
|
||||||
|
// ErrInvalidResponseContent defines an error raised when Portainer excepts a JSON array and get something else.
|
||||||
|
ErrInvalidResponseContent = portainer.Error("Invalid Docker response")
|
||||||
)
|
)
|
||||||
|
|
||||||
func extractJSONField(jsonObject map[string]interface{}, key string) map[string]interface{} {
|
func extractJSONField(jsonObject map[string]interface{}, key string) map[string]interface{} {
|
||||||
|
@ -39,8 +41,17 @@ func getResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
responseObject := responseData.([]interface{})
|
switch responseObject := responseData.(type) {
|
||||||
return responseObject, nil
|
case []interface{}:
|
||||||
|
return responseObject, nil
|
||||||
|
case map[string]interface{}:
|
||||||
|
if responseObject["message"] != nil {
|
||||||
|
return nil, portainer.Error(responseObject["message"].(string))
|
||||||
|
}
|
||||||
|
return nil, ErrInvalidResponseContent
|
||||||
|
default:
|
||||||
|
return nil, ErrInvalidResponseContent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResponseBodyAsGenericJSON(response *http.Response) (interface{}, error) {
|
func getResponseBodyAsGenericJSON(response *http.Response) (interface{}, error) {
|
||||||
|
|
Loading…
Reference in New Issue