Skip to content

Commit

Permalink
[fix] improve error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Jan 24, 2024
1 parent 976ea3a commit 81bea39
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions healthchecker/healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/flashbots/node-healthchecker/httplogger"
"github.com/flashbots/node-healthchecker/logutils"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -129,23 +130,33 @@ func (h *Healthchecker) handleHTTPRequest(w http.ResponseWriter, r *http.Request
}()
}

errors := []error{}
errs := []error{}
for count > 0 {
count--
if res := <-results; res != nil {
errors = append(errors, res)
errs = append(errs, res)
}
}
close(results)

if len(errors) == 0 {
if len(errs) == 0 {
return
}

l := logutils.LoggerFromRequest(r)

w.Header().Set("Content-Type", "application/text")
w.WriteHeader(http.StatusInternalServerError)
for idx, err := range errors {
for idx, err := range errs {
line := fmt.Sprintf("%d: %s\n", idx, err)
w.Write([]byte(line))
_, err := w.Write([]byte(line))
if err != nil {
l.Error("Failed to write the response body", zap.Error(err))
}
}

l.Warn(
"Failed the healthcheck due to upstream error(s)",
zap.Error(errors.Join(errs...)),
)
}

0 comments on commit 81bea39

Please sign in to comment.