Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func serveMetrics() {
}))
http.Handle("/chanz", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
slog.Debug("display channelz data on /chanz")
w.Write([]byte(grpc.UpdateMetrics(mClient)))
if _, err := w.Write([]byte(grpc.UpdateMetrics(mClient))); err != nil {
slog.Error("failed to write channelz response", "error", err)
}
}))
//nolint:gosec // Ignoring G114
if err := http.ListenAndServe(*metricFlag, nil); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func DisplayRoutes(w http.ResponseWriter, r *http.Request) {

// We still report it as a 404
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(strings.Join(filteredRoutes, "\n")))
if _, err := w.Write([]byte(strings.Join(filteredRoutes, "\n"))); err != nil {
slog.Error("failed to write routes response", "error", err)
}
}

func SetupRoutes(r *chi.Mux, client *grpc.Client) {
Expand Down
24 changes: 18 additions & 6 deletions routes_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func writeBeacon(w http.ResponseWriter, beacon *grpc.HexBeacon, nextTime int64,
}

w.WriteHeader(http.StatusOK)
w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("failed to write beacon response", "error", err)
}
}

func GetLatest(c *grpc.Client, isV2 bool) func(http.ResponseWriter, *http.Request) {
Expand Down Expand Up @@ -200,7 +202,9 @@ func GetChains(c *grpc.Client) func(http.ResponseWriter, *http.Request) {
return
}

w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("failed to write chains response", "error", err)
}
}
}

Expand Down Expand Up @@ -261,7 +265,9 @@ func GetHealth(c *grpc.Client) func(http.ResponseWriter, *http.Request) {
return
}

w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("[GetHealth] failed to write health response", "error", err)
}
}
}

Expand All @@ -280,7 +286,9 @@ func GetBeaconIds(c *grpc.Client) func(http.ResponseWriter, *http.Request) {
http.Error(w, "Failed to produce beacon ids", http.StatusInternalServerError)
return
}
w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("[GetBeaconIds] failed to write beacon ids response", "error", err)
}
}
}

Expand All @@ -307,7 +315,9 @@ func GetInfoV1(c *grpc.Client) func(http.ResponseWriter, *http.Request) {
return
}

w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("[GetInfoV1] failed to write chain info response", "error", err)
}
}
}

Expand All @@ -334,7 +344,9 @@ func GetInfoV2(c *grpc.Client) func(http.ResponseWriter, *http.Request) {
return
}

w.Write(json)
if _, err := w.Write(json); err != nil {
slog.Error("[GetInfoV2] failed to write chain info response", "error", err)
}
}
}

Expand Down