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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user