Skip to content

Commit

Permalink
Improve 502 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Sep 9, 2023
1 parent af4ffa4 commit 26865e8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions casdoorsdk/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ func (c *Client) DoPostBytesRaw(url string, contentType string, body io.Reader)
}
}(resp.Body)

respByte, err := ioutil.ReadAll(resp.Body)
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return respByte, nil
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusForbidden {
return nil, fmt.Errorf("%s", string(respBytes))
}

return respBytes, nil
}

// doGetBytesRawWithoutCheck is a general function to get response from param url through HTTP Get method without checking response status
Expand Down Expand Up @@ -207,6 +211,10 @@ func (c *Client) doGetBytesRawWithoutCheck(url string) ([]byte, error) {
return nil, err
}

if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusForbidden {
return nil, fmt.Errorf("%s", string(respBytes))
}

return respBytes, nil
}

Expand Down

0 comments on commit 26865e8

Please sign in to comment.