Improve log messages

This commit is contained in:
Bendodroid 2023-11-04 22:30:52 +01:00
parent 26a9cf4911
commit 930e81bd7f
Signed by: bendodroid
GPG key ID: 3EEE19A0F73D5FFC

View file

@ -34,6 +34,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalln("Could not parse provided JSON") log.Fatalln("Could not parse provided JSON")
} }
if !slices.Contains(spaceApiResponse.APICompatibility, "14") { if !slices.Contains(spaceApiResponse.APICompatibility, "14") {
log.Fatalln("Provided JSON doesn't specify compatibility with API version 14") log.Fatalln("Provided JSON doesn't specify compatibility with API version 14")
} }
@ -75,7 +76,7 @@ func main() {
body, err := io.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
log.Println("Failed to read body status update request from", r.RemoteAddr) log.Println("Failed to read request body from", r.RemoteAddr)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = io.WriteString(w, "Failed reading HTTP request body") _, _ = io.WriteString(w, "Failed reading HTTP request body")
return return
@ -83,6 +84,7 @@ func main() {
newState, err := strconv.ParseBool(string(body)) newState, err := strconv.ParseBool(string(body))
if err != nil { if err != nil {
log.Println("Failed to parse request body from", r.RemoteAddr)
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
_, _ = io.WriteString(w, "HTTP request body should either be true or false") _, _ = io.WriteString(w, "HTTP request body should either be true or false")
return return