psu/common/customerrors.go

27 lines
433 B
Go
Raw Normal View History

2019-07-21 02:00:04 +00:00
package common
import (
"encoding/json"
"log"
"net/http"
)
// CheckError checks if an error occurred (it's not nil)
func CheckError(err error) {
if err != nil {
log.Fatalln(err)
}
}
func CheckResponseForErrors(resp *http.Response) error {
if 300 <= resp.StatusCode {
respBody := GenericError{}
err := json.NewDecoder(resp.Body).Decode(&respBody)
if err != nil {
return err
}
return &respBody
}
return nil
}