Skip to content

Commit

Permalink
add workaround for mistyped response parameter
Browse files Browse the repository at this point in the history
the deploy/single/custom endpoint returns a string boolean on the `success` field on error which causes type mismatches when unmarshalling into the standard response object
  • Loading branch information
caguiclajmg committed Jun 28, 2022
1 parent 6e5dcc5 commit 4902788
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"reflect"
"strconv"
"strings"

"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -132,6 +134,29 @@ func (client *Client) do(method string, path string, params map[string]string, h
return &msg, nil
}

// FIXME: Some endpoints return a string boolean on the `success`` field
var raw map[string]interface{}
err = json.Unmarshal(bytes, &raw)
if err != nil {
return nil, err
}
if val, ok := raw["success"]; ok {
if reflect.ValueOf(val).Kind() == reflect.String {
success, err := strconv.ParseBool(val.(string))
if err != nil {
success = false
}
raw["success"] = success
bytes, err := json.Marshal(raw)
if err != nil {
return nil, err
}

msg := json.RawMessage(bytes)
return &msg, nil
}
}

msg := json.RawMessage(bytes)
return &msg, nil
}
Expand Down

0 comments on commit 4902788

Please sign in to comment.