Preserve request IDs on raw client errors

Merged
RO
7mo ago
+150-12

Summary

  • preserve X-Request-Id on raw Go client HTTP failures in Client.singleRequest
  • reuse the existing basecamp.Error.RequestID field for raw Get/Post/Put/Delete paths
  • 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 on basecamp.Error
  • captured X-Request-Id in singleRequest()
  • 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-Id in Client.singleRequest and attach it to all non-2xx errors from raw Get/Post/Put/Delete (including 304, auth, rate limit, gateway, and not found).
    • Keep checkResponse() behavior; add tests confirming IDs are preserved on both paths.
  • Refactors

    • Add basecamp.Error.withRequestID() and centralize the header via a requestIDHeader constant used in the client and helpers.
    • Fix minor SDK lint issues in touched files.