fix(http): downgrade canOnboard check to warning log level (#1859)

This commit is contained in:
soup 2024-12-06 13:01:45 +01:00 committed by GitHub
parent ac1974c8d5
commit 99a9e6bc0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -156,6 +156,10 @@ func (h authHandler) onboard(w http.ResponseWriter, r *http.Request) {
func (h authHandler) canOnboard(w http.ResponseWriter, r *http.Request) {
if status, err := h.onboardEligible(r.Context()); err != nil {
if status == http.StatusServiceUnavailable {
h.encoder.StatusWarning(w, status, err.Error())
return
}
h.encoder.StatusError(w, status, err)
return
}

View file

@ -130,3 +130,16 @@ func (e encoder) StatusError(w http.ResponseWriter, status int, err error) {
return
}
}
func (e encoder) StatusWarning(w http.ResponseWriter, status int, message string) {
resp := errorResponse{
Status: status,
Message: message,
}
e.log.Warn().Str("warning", message).Int("status", status).Msg("server warning")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(status)
json.NewEncoder(w).Encode(resp)
}