Skip to content

Commit

Permalink
Need to review this... but it will fix some tests that started failin…
Browse files Browse the repository at this point in the history
…g after code handling changes.
  • Loading branch information
jmigueprieto committed Nov 6, 2024
1 parent 9b70a01 commit 1c79d79
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sdk/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 1c79d79

Please sign in to comment.