diff --git a/v2/api/client.go b/v2/api/client.go index b71a093..64121d2 100644 --- a/v2/api/client.go +++ b/v2/api/client.go @@ -249,11 +249,18 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { log.Printf("[ERROR] Call to %s returned status %d. %s", keyfactorPath, resp.StatusCode, stringMessage) return nil, errors.New(stringMessage) } else if resp.StatusCode == http.StatusUnauthorized { - _, derr := httputil.DumpResponse(resp, true) + dmp, derr := httputil.DumpResponse(resp, true) if derr != nil { return nil, derr } - err = errors.New("401 - Unauthorized: Access is denied due to invalid credentials") + //convert response to string + if dmp != nil { + respStr := string(dmp) + errMsg := fmt.Sprintf("http %d: %s", resp.StatusCode, respStr) + return nil, errors.New(errMsg) + } + errMsg := fmt.Sprintf("http %d: %s", resp.StatusCode, "Unauthorized: Access is denied due to invalid credentials") + err = errors.New(errMsg) return nil, err } else { var errorMessage map[string]interface{} // Decode JSON body to handle issue diff --git a/v2/api/client_models.go b/v2/api/client_models.go index dcfdf07..fc9132c 100644 --- a/v2/api/client_models.go +++ b/v2/api/client_models.go @@ -3,29 +3,29 @@ package api // StringTuple is a struct holding two string elements used by the Keyfactor // Go Client library for data types requiring a tuple of strings type StringTuple struct { - Elem1 string - Elem2 string + Elem1 string `json:"elem1,omitempty"` + Elem2 string `json:"elem2,omitempty"` } // apiHeaders is a struct that holds an array of StringTuples used // to modularize the passing of custom API headers. type apiHeaders struct { - Headers []StringTuple + Headers []StringTuple `json:"headers,omitempty"` } // apiQuery is a struct that holds an array of StringTuples used // to modularize the passing of custom URL query parameters. type apiQuery struct { - Query []StringTuple + Query []StringTuple `json:"query,omitempty"` } // request is a structure that holds required information for communicating with // the Keyfactor API. Included inside this struct is a pointer to an APIHeaders struct, a payload as an // interface, and other configuration information for the API call. type request struct { - Method string - Endpoint string - Headers *apiHeaders - Query *apiQuery - Payload interface{} + Method string `json:"method"` + Endpoint string `json:"endpoint"` + Headers *apiHeaders `json:"headers,omitempty"` + Query *apiQuery `json:"query,omitempty"` + Payload interface{} `json:"payload,omitempty"` }