Skip to content

Preserve request IDs on raw client errors#277

Open
robzolkos wants to merge 2 commits intobasecamp:mainfrom
robzolkos:sdk-surface-request-id-on-errors
Open

Preserve request IDs on raw client errors#277
robzolkos wants to merge 2 commits intobasecamp:mainfrom
robzolkos:sdk-surface-request-id-on-errors

Conversation

@robzolkos
Copy link
Copy Markdown
Collaborator

@robzolkos robzolkos commented Apr 21, 2026

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. Adds tests for both checkResponse() and raw failure 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() to safely set RequestID.
    • Fix minor SDK lint issues in touched files.

Written for commit 4867849. Summary will update on new commits.

@github-actions github-actions Bot added go bug Something isn't working labels Apr 21, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@robzolkos robzolkos marked this pull request as ready for review April 21, 2026 19:42
Copilot AI review requested due to automatic review settings April 21, 2026 19:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes request ID handling consistent across the SDK by preserving the X-Request-Id header on structured *basecamp.Error values produced from the raw HTTP client path (Client.singleRequest), matching the behavior already present in checkResponse().

Changes:

  • Add (*basecamp.Error).withRequestID() helper to attach a request ID without mutating the original error.
  • Capture X-Request-Id in Client.singleRequest() and propagate it onto all non-2xx structured errors in that path.
  • Add/extend tests to ensure request IDs are preserved for both checkResponse() and raw client failures.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
go/pkg/basecamp/client.go Capture X-Request-Id from responses and attach it to all raw-client non-2xx *Error returns.
go/pkg/basecamp/errors.go Introduce withRequestID() helper to set RequestID safely via shallow copy.
go/pkg/basecamp/client_test.go Add coverage ensuring raw-client error paths include the request ID across several status/method combinations.
go/pkg/basecamp/helpers_test.go Add coverage ensuring checkResponse() continues to record RequestID from response headers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants