refactor(reports): dedupe claim-error-code parsing into parseJsonResponse - #6452
Merged
Conversation
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.
Small reduction in
apps/api/src/tools/reports/auth-client.ts:parseClaimErrorCodehand-rolled its own "read text, tolerate empty, JSON.parse, tolerate parse failure" logic — the exact same tolerant-parse shapeparseJsonResponsealready 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:
parseJsonResponsereturnsundefined->parsed?.errorisundefined->isClaimCode(undefined)isfalse->"unknown"(same as before).errorcode -> unchanged.error(or missingerror) ->"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 --noEmitinapps/api,bunx oxlinton the touched file,bun run fmt. Full CI validates the rest.Reviewer check:
bun test apps/api/src/tools/reports/auth-client.test.tsSummary by cubic
Deduplicates claim-error parsing in the reports auth client by routing
parseClaimErrorCodethroughparseJsonResponse. This removes duplicate tolerant JSON parsing and preserves behavior for all responses.Review notes
parseClaimErrorCodenow usesparseJsonResponse; empty or non-JSON bodies still return "unknown".errorcodes behave the same; unrecognized or missing values still return "unknown".apps/api/src/tools/reports/auth-client.tsis modified. Runbun test apps/api/src/tools/reports/auth-client.test.tsto verify the claim-error cases.Written for commit 04ebd74. Summary will update on new commits.