fix: harden API response error handling - #24
Open
gtmdev-br wants to merge 10 commits into
Open
Conversation
Verified scoped implementation and script-generated diagnostic artifacts for bounty issue 123a-bcd#1.
- Add configurable max cardinality limit for metric tags (default: 1000) - Enforce limit before samples are queued to prevent DB growth - Track unique tag combinations per metric name deterministically - Add WithMaxCardinality option for configuration - Update CollectorStats to expose cardinality metrics - Add comprehensive tests for cardinality limiting behavior Closes 123a-bcd#14
- Add parseErrorResponse() to safely parse JSON and text error bodies into ApiError - Modify request<T>() to check response.ok and throw on non-2xx HTTP statuses - Add isApiError() type guard to distinguish API errors from native Error types - HTTP errors bypass retry logic (they are deterministic, not transient) - Error interceptors (401, 429) now reliably fire for HTTP error responses - Add validation test suite covering: 200, 401, 429, 500, 404, timeout, network errors - Include diagnostic build artifact Closes 123a-bcd#1
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.
Summary
Harden the shared frontend API client so non-2xx HTTP responses are rejected as errors instead of flowing through as successful
ApiResponse<T>values. This ensures error interceptors (401, 429) fire reliably and callers no longer need to duplicate status checks.Changes
parseErrorResponse()— safely parses JSON and text error response bodies intoApiErrorobjects, preservingrequestId,details,path, and actionablesuggestionfields.request<T>()— checksresponse.okafter fetch; non-2xx responses are parsed, run through the error interceptor chain, and thrown immediately (bypassing retry logic since HTTP errors are deterministic).isApiError()type guard — distinguishes ourApiErrorobjects from native Error types (DOMException, TypeError) to prevent false positives in the retry logic.diagnostic/build-c6be4f51.jsonTesting
npx tsc --noEmit— passes (zero errors)npm run build— builds successfullynpx tsx src/services/__tests__/api-error-handling.test.ts— 8/8 tests passChecklist
Closes #1