Skip to content

Fix error message lost on consumed response body#6

Closed
farhatraiyan wants to merge 3 commits into
mainfrom
fix-error-message-from-consumed-response
Closed

Fix error message lost on consumed response body#6
farhatraiyan wants to merge 3 commits into
mainfrom
fix-error-message-from-consumed-response

Conversation

@farhatraiyan

@farhatraiyan farhatraiyan commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Every method calls response.json() then HttpError.from(response) when a 200 response contains an errors[] envelope. Since .json() consumes the body, HttpError.from() gets an empty clone and falls back to "200 OK" instead of the actual FedEx error text.
  • Use HttpError.from(response, json) (added in @stores.com/http-error@1.2.0) to pass the already-parsed body directly, avoiding the consumed-body problem without cloning.
  • Removes the interim createHttpError helper — http-error now handles this natively.
  • Affects all 6 API methods: cancelShipment, createShipment, groundEndOfDayClose, rateAndTransitTimes, trackByTrackingNumber, validateAddress.

Commits

  1. RED — 6 TODO tests asserting err.message matches the FedEx error text (all fail with "200 OK")
  2. GREEN — Replace createHttpError with HttpError.from(response, json), bump @stores.com/http-error to ~1.2.0, remove TODO markers

Test plan

  • All 6 "should include error message" tests pass
  • Existing mocked tests remain green
  • Publish @stores.com/fedex@0.5.1
  • Bump @stores.com/fedex in fulfillment-service (stores-com/fulfillment-service#885)

🤖 Generated with Claude Code

Every method calls response.json() then HttpError.from(response) when
the 200 response contains an errors array. The body is already consumed
so HttpError.from cannot re-read it, producing "200 OK" instead of the
actual error message. These 6 TODO tests assert the expected behavior
for each affected API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coveralls

coveralls commented May 26, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 26520875675

Coverage remained the same at 100.0%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 324
Covered Lines: 324
Line Coverage: 100.0%
Relevant Branches: 49
Covered Branches: 49
Branch Coverage: 100.0%
Branches in Coverage %: Yes
Coverage Strength: 19.69 hits per line

💛 - Coveralls

response.json() consumes the body, so the subsequent HttpError.from()
call gets an empty clone and falls back to "200 OK" as the message.
Replace with createHttpError() that builds the error from the already-
parsed JSON, preserving the actual FedEx error messages. Remove TODO
markers from the 6 tests that now pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mediocrebot mediocrebot force-pushed the fix-error-message-from-consumed-response branch from c6e449e to 7b2d15e Compare May 27, 2026 04:36
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@farhatraiyan farhatraiyan deleted the fix-error-message-from-consumed-response branch May 27, 2026 15:29
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