From 1c79d79a04f7d1ba93a7a9f8e4c1d60362fe4f53 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Tue, 5 Nov 2024 21:38:16 -0300 Subject: [PATCH] Need to review this... but it will fix some tests that started failing after code handling changes. --- sdk/client/api_client.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sdk/client/api_client.go b/sdk/client/api_client.go index e3d2f4dd..16040e43 100644 --- a/sdk/client/api_client.go +++ b/sdk/client/api_client.go @@ -129,23 +129,30 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { if strings.Contains(contentType, "application/xml") { - if err = xml.Unmarshal(b, v); err != nil { - return err + if len(b) > 0 { + if err = xml.Unmarshal(b, v); err != nil { + return err + } } return nil } else if strings.Contains(contentType, "application/json") { - if err = json.Unmarshal(b, v); err != nil { - return err + if len(b) > 0 { + if err = json.Unmarshal(b, v); err != nil { + return err + } } return nil } else if strings.Contains(contentType, "text/plain") { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return errors.New("undefined response type") + if len(b) == 0 { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return errors.New("undefined response type") + } + rv.Elem().SetString(string(b)) } - rv.Elem().SetString(string(b)) return nil } + return errors.New("undefined response type") }