Feature/put post (#9)
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HTTPClientError custom error to handle with response status
|
||||
// HTTPClientError custom error to handle with response status.
|
||||
type HTTPClientError struct {
|
||||
StatusCode int
|
||||
Err error
|
||||
@@ -23,12 +23,14 @@ func (e *HTTPClientError) Error() string {
|
||||
|
||||
func makeHTTPClientError(url string, resp *http.Response) error {
|
||||
var resError error
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
resError = fmt.Errorf("HTTP request failure on %s with status %d\nCannot parse body with: %w", url, resp.StatusCode, err)
|
||||
} else {
|
||||
resError = fmt.Errorf("HTTP request failure on %s with status %d\nBody: %v", url, resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
return &HTTPClientError{
|
||||
StatusCode: resp.StatusCode,
|
||||
Err: resError,
|
||||
|
||||
Reference in New Issue
Block a user