Preserve request IDs on raw client errors#277
Open
robzolkos wants to merge 2 commits intobasecamp:mainfrom
Open
Preserve request IDs on raw client errors#277robzolkos wants to merge 2 commits intobasecamp:mainfrom
robzolkos wants to merge 2 commits intobasecamp:mainfrom
Conversation
There was a problem hiding this comment.
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-IdinClient.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
X-Request-Idon raw Go client HTTP failures inClient.singleRequestbasecamp.Error.RequestIDfield for rawGet/Post/Put/DeletepathscheckResponse()and raw client failuresProblem
The Go SDK already had a
RequestIDfield onbasecamp.Error, and generated-service paths populated it viacheckResponse().But the raw HTTP client path used by
AccountClient.Get/Post/Put/Deletebuilt fresh SDK errors insingleRequest()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
withRequestID()helper onbasecamp.ErrorX-Request-IdinsingleRequest()checkResponse()still records request idsRequestIDWhy 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
Summary by cubic
Preserves
X-Request-Idon errors from raw client requests so request IDs are consistent across the SDK and visible to tools like the CLI. Adds tests for bothcheckResponse()and raw failure paths.Bug Fixes
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).checkResponse()behavior; add tests confirming IDs are preserved on both paths.Refactors
basecamp.Error.withRequestID()to safely setRequestID.Written for commit 4867849. Summary will update on new commits.