From 99a9e6bc0f7dca3a0188feaadaf3b7b6a2dd32f4 Mon Sep 17 00:00:00 2001 From: soup Date: Fri, 6 Dec 2024 13:01:45 +0100 Subject: [PATCH] fix(http): downgrade canOnboard check to warning log level (#1859) --- internal/http/auth.go | 4 ++++ internal/http/encoder.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/internal/http/auth.go b/internal/http/auth.go index 70bd3b7..07e508c 100644 --- a/internal/http/auth.go +++ b/internal/http/auth.go @@ -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 } diff --git a/internal/http/encoder.go b/internal/http/encoder.go index 2fdb5b3..08ff0d8 100644 --- a/internal/http/encoder.go +++ b/internal/http/encoder.go @@ -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) +}