Skip to content

[0 BOUNTY] [TypeScript] Harden API response error handling#19

Open
alKanz17 wants to merge 1 commit into
2lll5:mainfrom
alKanz17:fix/api-error-handling
Open

[0 BOUNTY] [TypeScript] Harden API response error handling#19
alKanz17 wants to merge 1 commit into
2lll5:mainfrom
alKanz17:fix/api-error-handling

Conversation

@alKanz17

Copy link
Copy Markdown

What this does

Prevents 4xx/5xx HTTP responses from flowing through response interceptors as successful data. Non-OK responses are now normalized into ApiError objects and thrown through the error interceptor chain.

How it works

  • parseResponse() now throws an ApiError for !response.ok so callers no longer need to duplicate status checks
  • Added parseErrorResponse() that preserves request IDs, status codes, structured JSON error payloads from the backend, and actionable suggestions
  • Added getSuggestionForStatus() with human-readable messages for 401, 403, 404, 429, and 5xx errors
  • Added isApiError() type guard so downstream code can distinguish ApiErrors from network/abort errors
  • Error interceptors (401 token refresh, 429 rate limiting) are now reliably exercised on every error response

Testing

  • tsc -b passes with zero errors
  • vite build succeeds
  • The existing error interceptor for 401 (token refresh) and 429 (backoff) now fires correctly because non-OK responses are thrown instead of returned as ApiResponse

Closes #1

- parseResponse() now throws ApiError for non-OK HTTP responses
  so error interceptors (401, 429) are consistently exercised
- Added parseErrorResponse() that preserves request IDs, status codes,
  structured JSON error payloads, and actionable suggestions
- Added getSuggestionForStatus() for common HTTP error codes
- Added isApiError() type guard for clean error handling
- Error interceptor chain now runs on both network errors and
  HTTP error responses, ensuring uniform behavior

Closes Saiaaax#1
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.

[$40 BOUNTY] [TypeScript] Harden API response error handling

1 participant