Remove unused CheckResponseForErrors error handling helper

It's logic is now implemented into the Client
This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-02 13:14:23 -04:00
parent 93f08172ac
commit 5dc5f43763

View File

@ -1,13 +1,8 @@
package common package common
import ( import (
"bytes"
"encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/http"
) )
// CheckError checks if an error occurred (it's not nil) // 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())) 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
}