refactor: clean code
This commit is contained in:
@@ -20,7 +20,7 @@ func (c *Client) getAccessToken() error {
|
||||
|
||||
resp := &getAPIAccessTokenResponse{}
|
||||
if err := json.Unmarshal(res.Body(), &resp); err != nil {
|
||||
return fmt.Errorf("goedge api error: failed to parse response: %w", err)
|
||||
return fmt.Errorf("goedge api error: failed to unmarshal response: %w", err)
|
||||
} else if resp.GetCode() != 200 {
|
||||
return fmt.Errorf("goedge get access token failed: code: %d, message: %s", resp.GetCode(), resp.GetMessage())
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (c *Client) sendRequest(method string, path string, params interface{}) (*r
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("goedge api error: failed to send request: %w", err)
|
||||
} else if resp.IsError() {
|
||||
return resp, fmt.Errorf("goedge api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.Body())
|
||||
return resp, fmt.Errorf("goedge api error: unexpected status code: %d, resp: %s", resp.StatusCode(), resp.String())
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
@@ -94,7 +94,7 @@ func (c *Client) sendRequestWithResult(method string, path string, params interf
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(resp.Body(), &result); err != nil {
|
||||
return fmt.Errorf("goedge api error: failed to parse response: %w", err)
|
||||
return fmt.Errorf("goedge api error: failed to unmarshal response: %w", err)
|
||||
} else if errcode := result.GetCode(); errcode != 200 {
|
||||
return fmt.Errorf("goedge api error: code='%d', message='%s'", errcode, result.GetMessage())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user