Skip to content

web: log discarded errors, include response body on NetBox decode failure

Aiho Tehisaru requested to merge fix/error-logging-and-netbox-body-snippet into trunk

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:

  1. No logs at all. Every http.Error(w, "internal error", ...) / "fetching X: "+err.Error() call site across internal/web discarded the actual err — nothing was logged server-side. Added log.Printf at each of those (racks.go, devices.go's writeHTTPError chokepoint and rackDevicesHandler, audit.go, settings.go, server.go's render()).
  2. The error itself was uninformative. invalid character '<' looking for beginning of value just means NetBox returned a 2xx response with an HTML body instead of JSON (wrong NETBOX_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 >=300 status 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

🤖 Generated with Claude Code

https://claude.ai/code/session_01U9buZPRQy7YXLodkSPFFik

Merge request reports

Loading