Skip to content

Commit 502afe2

Browse files
authored
feat: Print the response log when the api call failed (#139)
* update the client log * receive the responseBody and stateCode from the agent to format error message
1 parent 2dc8f5d commit 502afe2

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

client/client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ func (c *APIClient) CallAPI(request *http.Request) (*http.Response, error) {
6363
}
6464

6565
resp, err := c.cfg.HTTPClient.Do(request)
66-
if err != nil {
67-
return resp, err
68-
}
6966

7067
if c.cfg.Debug {
7168
dump, err := httputil.DumpResponse(resp, true)
@@ -74,6 +71,7 @@ func (c *APIClient) CallAPI(request *http.Request) (*http.Response, error) {
7471
}
7572
log.Printf("\n%s\n", string(dump))
7673
}
74+
7775
return resp, err
7876
}
7977

internal/error/generic_error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func (g GenericAPIError) Error() string {
1818
}
1919

2020
// FormatErrorMessage format error message using title and detail when model implements rfc7807
21-
func FormatErrorMessage(status string, v interface{}) string {
22-
str := ""
21+
func FormatErrorMessage(status string, responseBody string, v interface{}) string {
22+
str := responseBody
2323
metaValue := reflect.ValueOf(v).Elem()
2424

2525
if metaValue.Kind() == reflect.Struct {

0 commit comments

Comments
 (0)