Check json encoder errors

This commit is contained in:
Juan Font Alonso 2022-08-14 12:47:04 +02:00
parent eb8d8f142c
commit 20d2615081

View File

@ -313,7 +313,15 @@ func (h *Headscale) handleNoiseAuthKey(
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
json.NewEncoder(writer).Encode(resp)
err = json.NewEncoder(writer).Encode(resp)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to encode response")
return
}
log.Info().
Caller().
@ -343,7 +351,13 @@ func (h *Headscale) handleNoiseNodeValidRegistration(
Inc()
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
json.NewEncoder(writer).Encode(resp)
err := json.NewEncoder(writer).Encode(resp)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to encode response")
}
}
func (h *Headscale) handleNoiseMachineRegistrationNew(
@ -370,7 +384,13 @@ func (h *Headscale) handleNoiseMachineRegistrationNew(
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
json.NewEncoder(writer).Encode(resp)
err := json.NewEncoder(writer).Encode(resp)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to encode response")
}
}
func (h *Headscale) handleNoiseNodeLogOut(
@ -430,7 +450,13 @@ func (h *Headscale) handleNoiseNodeRefreshKey(
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
json.NewEncoder(writer).Encode(resp)
err := json.NewEncoder(writer).Encode(resp)
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to encode response")
}
}
func (h *Headscale) handleNoiseNodeExpired(