mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
27 lines
433 B
Go
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
|
|
}
|