maintain underlying error structs to allow for type conversion (#293)

* maintain underlying error structs to allow for type conversion and
defensive error checking

* allow Error.Is for Azure responses

* update readme, add tests to ensure type conversion

* fix whitespacing

* read me

* add import to readme example
This commit is contained in:
Quest Henkart
2023-05-04 02:48:59 +08:00
committed by GitHub
parent 24aa2005cc
commit a24581dce2
4 changed files with 46 additions and 10 deletions

View File

@@ -149,15 +149,16 @@ func (c *Client) handleErrorResp(resp *http.Response) error {
var errRes ErrorResponse
err := json.NewDecoder(resp.Body).Decode(&errRes)
if err != nil || errRes.Error == nil {
reqErr := RequestError{
reqErr := &RequestError{
HTTPStatusCode: resp.StatusCode,
Err: err,
}
if errRes.Error != nil {
reqErr.Err = errRes.Error
}
return fmt.Errorf("error, %w", &reqErr)
return reqErr
}
errRes.Error.HTTPStatusCode = resp.StatusCode
return fmt.Errorf("error, status code: %d, message: %w", resp.StatusCode, errRes.Error)
return errRes.Error
}