Skip to content

refactor(reports): dedupe claim-error-code parsing into parseJsonResponse - #6452

Merged
pedrofrxncx merged 1 commit into
mainfrom
refactor/dedupe-claim-error-parse-w4
Aug 24, 2026
Merged

refactor(reports): dedupe claim-error-code parsing into parseJsonResponse#6452
pedrofrxncx merged 1 commit into
mainfrom
refactor/dedupe-claim-error-parse-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Small reduction in apps/api/src/tools/reports/auth-client.ts: parseClaimErrorCode hand-rolled its own "read text, tolerate empty, JSON.parse, tolerate parse failure" logic — the exact same tolerant-parse shape parseJsonResponse already implements two functions below it (and is already used by every other response handler in this file, e.g. fetchCommerceDiscoveryAuth's token check, bindCommerceDiscoveryResource, fetchCommerceDiscoveryConnectionStatus).

Why a maintainer wants it: one tolerant-parse implementation instead of two copies drifting apart — a future robustness fix (e.g. a body-size cap) only needs to land once.

Behavior preserved for every input:

  • Empty/unparsable body -> parseJsonResponse returns undefined -> parsed?.error is undefined -> isClaimCode(undefined) is false -> "unknown" (same as before).
  • Parsed JSON with a recognized error code -> unchanged.
  • Parsed JSON with an unrecognized error (or missing error) -> "unknown" (same as before).

-9 / +5 lines, no behavior change, no new exports.

How I verified: bun test apps/api/src/tools/reports/auth-client.test.ts (26 pass, including the 403/409/400/non-JSON-body claim-error tests that exercise this exact function), bunx tsc --noEmit in apps/api, bunx oxlint on the touched file, bun run fmt. Full CI validates the rest.

Reviewer check: bun test apps/api/src/tools/reports/auth-client.test.ts


Summary by cubic

Deduplicates claim-error parsing in the reports auth client by routing parseClaimErrorCode through parseJsonResponse. This removes duplicate tolerant JSON parsing and preserves behavior for all responses.

Review notes

  • parseClaimErrorCode now uses parseJsonResponse; empty or non-JSON bodies still return "unknown".
  • Recognized error codes behave the same; unrecognized or missing values still return "unknown".
  • No API or export changes; only apps/api/src/tools/reports/auth-client.ts is modified. Run bun test apps/api/src/tools/reports/auth-client.test.ts to verify the claim-error cases.

Written for commit 04ebd74. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx merged commit d6556b9 into main Aug 24, 2026
33 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/dedupe-claim-error-parse-w4 branch August 24, 2026 15:48
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.

1 participant