Harden API response error handling for non-2xx status codes#12
Open
GautamKumarOffical wants to merge 2 commits into
Open
Harden API response error handling for non-2xx status codes#12GautamKumarOffical wants to merge 2 commits into
GautamKumarOffical wants to merge 2 commits into
Conversation
added 2 commits
June 22, 2026 14:32
Non-ok HTTP responses now get parsed into ApiError objects, run through the error interceptor chain, and thrown as errors instead of being returned as successful ApiResponse values. - Add parseErrorResponse to safely extract message/details/requestId - Add ApiHttpError class that wraps ApiError and serializes to JSON - Error interceptors now fire for 401/429/etc like they should - Timeout and network-error paths remain unchanged - Add vitest with tests for 2xx, 401, 429, 500, timeout, and network errors Closes #1 Signed-off-by: Gautam Kumar <gautamkumarofficial@users.noreply.github.com>
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
Fix
request<T>()so non-OK HTTP responses are rejected instead of being silently returned as successfulApiResponse<T>values. This ensures error interceptors (401, 429, etc.) actually fire and callers get structuredApiErrorobjects with message, details, requestId, and suggestion fields.Changes
parseErrorResponse()that safely parses JSON and text error bodies intoApiErrorobjectsApiHttpErrorclass extendingErrorthat wrapsApiErrorand serializes back to JSONrequest()to checkresponse.okafter fetch — non-2xx responses now throw through the error interceptor chainnormalizeError) remain unchangedTesting
npm run test— 10/10 tests passnpx tsc -b— TypeScript compiles cleanpython3 build.py -m frontend— frontend build passesChecklist