Skip to content

Commit

Permalink
fix: status error with output
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 6, 2023
1 parent ace4c17 commit 5a8a483
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ func (c *Client) getResource(resPath string) ([]byte, error) {
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status: %d output: %q", resp.StatusCode, resp.Body)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return body, nil
var statusErr error
if resp.StatusCode != http.StatusOK {
statusErr = fmt.Errorf("unexpected status: %d", resp.StatusCode)
}

return body, statusErr
}

func (c *Client) postResource(resPath string, requestBody interface{}) ([]byte, error) {
Expand All @@ -59,16 +60,17 @@ func (c *Client) postResource(resPath string, requestBody interface{}) ([]byte,
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("unexpected status: %d output: %q", resp.StatusCode, resp.Body)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return body, nil
var statusErr error
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
statusErr = fmt.Errorf("unexpected status: %d", resp.StatusCode)
}

return body, statusErr
}

func (c *Client) getServiceStatus(resPath string) (*api.MetaMessage, error) {
Expand Down

0 comments on commit 5a8a483

Please sign in to comment.