mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Remove unused CheckResponseForErrors error handling helper
It's logic is now implemented into the Client
This commit is contained in:
parent
93f08172ac
commit
5dc5f43763
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user