psu/common/customerrors.go
Juan Carlos Mejías Rodríguez c5b1dfaa82 Rewrite project in Go
2019-07-21 18:49:28 -04:00

27 lines
433 B
Go

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
}