Preserve request IDs on raw client errors
Summary
- preserve
X-Request-Idon raw Go client HTTP failures inClient.singleRequest - reuse the existing
basecamp.Error.RequestIDfield for rawGet/Post/Put/Deletepaths - add tests covering both
checkResponse()and raw client failures
Problem
The Go SDK already had a RequestID field on basecamp.Error, and generated-service paths populated it via checkResponse().
But the raw HTTP client path used by AccountClient.Get/Post/Put/Delete built fresh SDK errors in singleRequest() without copying the response request id. That made request-id handling inconsistent across the SDK and meant downstream consumers like the CLI could not reliably surface failing request ids for raw API calls.
What changed
- added a small
withRequestID()helper onbasecamp.Error - captured
X-Request-IdinsingleRequest() - attached the request id to all raw-client non-2xx SDK errors, including:
- 304 cache-miss errors
- 401/403/404/429/500
- 502/503/504 gateway errors
- generic non-2xx API errors
- added tests to verify:
checkResponse()still records request ids- raw client request failures now include
RequestID
Why this belongs in the SDK
By the time the CLI receives an error, it no longer has access to the original HTTP response headers. If we want all SDK consumers to be able to surface request ids consistently, the SDK has to preserve the header on its structured error type.
Testing
cd go && go test ./pkg/basecamp/...
Summary by cubic
Preserves X-Request-Id on errors from raw client requests so request IDs are consistent across the SDK and visible to tools like the CLI. Centralizes the header name and adds tests for both checkResponse() and raw paths.
-
Bug Fixes
- Capture
X-Request-IdinClient.singleRequestand attach it to all non-2xx errors from rawGet/Post/Put/Delete(including 304, auth, rate limit, gateway, and not found). - Keep
checkResponse()behavior; add tests confirming IDs are preserved on both paths.
- Capture
-
Refactors
- Add
basecamp.Error.withRequestID()and centralize the header via arequestIDHeaderconstant used in the client and helpers. - Fix minor SDK lint issues in touched files.
- Add