Feature/put post (#9)

This commit is contained in:
Yaroslav Rudenko
2021-10-02 14:27:00 +03:00
committed by GitHub
parent 8deb157f4d
commit 3bd1ace8d8
6 changed files with 107 additions and 28 deletions

View File

@@ -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,