Skip to content

API error handling enhancements - #21

Merged
cvidmar merged 2 commits into
masterfrom
feature/api-error-handling-enhancements
Sep 24, 2026
Merged

cvidmar merged 2 commits into
masterfrom
feature/api-error-handling-enhancements

Conversation

@cvidmar

@cvidmar cvidmar commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Description

fix(client): rebuild the request body before a rate-limit retry

do() retried a 429 by calling itself with the same *http.Request, whose body the
first attempt had already consumed. The retry went out with the original
Content-Length and no data, which HTTP/2 peers reject by resetting the stream:
"stream error: stream ID n; PROTOCOL_ERROR; received from peer". Every write
carrying a body — entry and asset upserts, localized field updates — failed
whenever it hit the rate limit, which is precisely when the retry was meant to
save it.

Rebuild the body from req.GetBody(), which net/http populates for the
*bytes.Buffer bodies this client sends, and fall back to the original API error
when it is absent rather than sending an empty request.

fix(client): close the response body when there is nothing to decode

do() closed the response body on the success path only when a decode target was
given, so every call passing nil — Publish, Unpublish, Delete and nine others —
leaked its response. A publish-heavy run keeps one HTTP/2 stream open per call
until the finalizer collects it, and on HTTP/1.1 the connection cannot be
reused. Drain and close on the way out instead.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactoring
  • ⚡ Performance
  • ✅ Tests
  • 🔧 Build/CI

Related Issue

Changes

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.

Notes

@cvidmar
cvidmar merged commit 0cea36f into master Sep 24, 2026
4 checks passed
@cvidmar
cvidmar deleted the feature/api-error-handling-enhancements branch September 24, 2026 08:41
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