Skip to content

Extract shared HTTP logic into doHTTP#70

Merged
hownowstephen merged 3 commits into
mainfrom
refactor-api-error-handling
Jun 1, 2026
Merged

Extract shared HTTP logic into doHTTP#70
hownowstephen merged 3 commits into
mainfrom
refactor-api-error-handling

Conversation

@hownowstephen

@hownowstephen hownowstephen commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • CustomerIO.request() and APIClient.doRequest() duplicated the same marshal → create request → set headers → execute → read body pipeline
  • Extracts doHTTP() in http.go that accepts an auth callback; both clients delegate to it
  • Auth (Basic vs Bearer) and error handling remain caller-specific
  • Also fixes minor bug: CustomerIO.request() was not setting User-Agent header on DELETE requests (nil body path)
  • Net -19 lines

Test plan

  • go test -race ./... passes
  • No public API changes — internal refactor only

Note

Low Risk
Internal refactor with no public API changes; behavior is intended to stay the same aside from the User-Agent fix on nil-body Track requests.

Overview
Consolidates duplicated HTTP request logic from CustomerIO.request() and APIClient.doRequest() into a new shared doHTTP helper in http.go. Both clients now delegate marshaling, request construction, User-Agent, auth via a caller preflight hook (Basic vs Bearer), execution, and body reads to that path while keeping their own status/error handling.

Also fixes CustomerIO requests with a nil body (e.g. DELETE) so User-Agent is set consistently, which the old nil-body branch skipped.

Reviewed by Cursor Bugbot for commit ce5caeb. Bugbot is set up for automated code reviews on this repo. Configure here.

Both CustomerIO.request() and APIClient.doRequest() duplicated the
same marshal → create request → set headers → execute → read body
pipeline. Extract doHTTP() that accepts an auth callback, then have
both clients delegate to it. Auth (Basic vs Bearer) and error
handling remain caller-specific.

Also fixes a minor bug: CustomerIO.request() was not setting the
User-Agent header on DELETE requests (nil body path).
@hownowstephen hownowstephen merged commit 410d1aa into main Jun 1, 2026
10 checks passed
@hownowstephen hownowstephen deleted the refactor-api-error-handling branch June 1, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants