Skip to content

Commit

Permalink
check return values
Browse files Browse the repository at this point in the history
  • Loading branch information
skandragon committed Feb 7, 2022
1 parent 111c300 commit e9e6f55
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ func (h *Health) HTTPHandler() http.HandlerFunc {
} else {
w.WriteHeader(418)
}
w.Write(data)
written, err := w.Write(data)
if err != nil {
log.Printf("when writing body: %v", err)
}
if written != len(data) {
log.Printf("unable to write entire body, %d of %d bytes", written, len(data))
}
}
}

Expand All @@ -201,7 +207,10 @@ func (hc *httpChecker) Check() error {
if err != nil {
return err
}
io.Copy(io.Discard, resp.Body)
_, err = io.Copy(io.Discard, resp.Body)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 200 && resp.StatusCode < 400 {
return nil
Expand Down

0 comments on commit e9e6f55

Please sign in to comment.