From 5dc5f43763dc1f7004ce683db1ce6fd85bd8ab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Fri, 2 Aug 2019 13:14:23 -0400 Subject: [PATCH] Remove unused CheckResponseForErrors error handling helper It's logic is now implemented into the Client --- common/customerrors.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/common/customerrors.go b/common/customerrors.go index 529ee84..6cbc47d 100644 --- a/common/customerrors.go +++ b/common/customerrors.go @@ -1,13 +1,8 @@ package common import ( - "bytes" - "encoding/json" - "errors" "fmt" - "io/ioutil" "log" - "net/http" ) // CheckError checks if an error occurred (it's not nil) @@ -16,23 +11,3 @@ func CheckError(err error) { log.Fatalln(fmt.Sprintf("Error: %s", err.Error())) } } - -func CheckResponseForErrors(resp *http.Response) error { - if 300 <= resp.StatusCode { - // Guess it's a GenericError - respBody := GenericError{} - err := json.NewDecoder(resp.Body).Decode(&respBody) - if err != nil { - // It's not a GenericError - bodyBytes, err := ioutil.ReadAll(resp.Body) - defer resp.Body.Close() - if err != nil { - return err - } - resp.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes)) - return errors.New(string(bodyBytes)) - } - return &respBody - } - return nil -}