web: log discarded errors, include response body on NetBox decode failure
Summary
Operator hit this on the racks page, with nothing in Rax's logs to explain it:
fetching racks: listing racks with role "vm-rack": invalid character '<'
looking for beginning of value
Two problems, both fixed here:
-
No logs at all. Every
http.Error(w, "internal error", ...)/"fetching X: "+err.Error()call site acrossinternal/webdiscarded the actualerr— nothing was logged server-side. Addedlog.Printfat each of those (racks.go,devices.go'swriteHTTPErrorchokepoint andrackDevicesHandler,audit.go,settings.go,server.go'srender()). -
The error itself was uninformative.
invalid character '<' looking for beginning of valuejust means NetBox returned a 2xx response with an HTML body instead of JSON (wrongNETBOX_URL, an auth/proxy interstitial page, etc.) —internal/netbox/client.go's JSON-decode error now includes the response status and a truncated body snippet, matching what the>=300status path already did.
Together: the next time this happens, the browser error (and the log line) will show what NetBox actually sent back instead of a bare JSON parser complaint.
Test plan
-
gofmt -s -w . && gofmt -l . && go build ./... && go vet ./... && go test ./...— clean