fix(backend): truncate HTTP error body in logs to 120 chars

Microsoft's 403 capacity page was logging hundreds of lines of HTML
per error. Both non-200 error paths now cap the body at 120 chars.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Shekhar Vaidya 2026-06-27 10:33:03 +05:30
parent d2c5c3c082
commit d4973ab42a

View file

@ -115,6 +115,15 @@ var (
linkCacheMu sync.RWMutex
)
// truncateBody caps a response body string for log output.
func truncateBody(s string) string {
const max = 120
if len(s) > max {
return s[:max] + "..."
}
return s
}
// --- Negative cache (60s normal / 90min Sentinel lockdown) ---
type negCacheEntry struct {
@ -736,7 +745,7 @@ func fetchSkuInfoFromMS(productID string) ([]byte, int, error) {
if resp.StatusCode != http.StatusOK {
if attempt == 2 {
return nil, http.StatusBadGateway, fmt.Errorf("Microsoft API returned HTTP %d: %s", resp.StatusCode, string(bodyBytes))
return nil, http.StatusBadGateway, fmt.Errorf("Microsoft API returned HTTP %d: %s", resp.StatusCode, truncateBody(string(bodyBytes)))
}
continue
}
@ -867,7 +876,7 @@ func fetchDownloadLinksFromMS(productID, skuID string) ([]byte, error) {
log.Printf("MS fetch /proxy: Sentinel block for product_id=%s — session evicted\n", productID)
return nil, &rateLimitError{"Sentinel marked this request as rejected."}
}
return nil, fmt.Errorf("Microsoft API returned HTTP %d: %s", resp.StatusCode, bodyStr)
return nil, fmt.Errorf("Microsoft API returned HTTP %d: %s", resp.StatusCode, truncateBody(bodyStr))
}
if len(bodyBytes) > 0 && bodyBytes[0] == '"' {