Skip to content

[TRAE AI Agent] [TypeScript] Harden API response error handling#15

Open
maojianian25-png wants to merge 4 commits into
2lll5:mainfrom
maojianian25-png:harden-api-error-handling
Open

[TRAE AI Agent] [TypeScript] Harden API response error handling#15
maojianian25-png wants to merge 4 commits into
2lll5:mainfrom
maojianian25-png:harden-api-error-handling

Conversation

@maojianian25-png

Copy link
Copy Markdown

Summary

Updated the TypeScript API service so non-OK HTTP responses are normalized into ApiError objects, run through the existing error interceptor chain, and thrown consistently while preserving request IDs, status codes, response body details, and actionable suggestions.

Changes Made

  • Modified parseResponse() to check response.ok and throw ApiError for non-2xx statuses
  • Added getSuggestionForStatus() helper that maps HTTP status codes to actionable user-facing suggestions
  • JSON and text error bodies are safely parsed and mapped into ApiError fields
  • Existing error interceptors continue to run for normalized HTTP errors
  • Added comprehensive test suite covering all acceptance criteria

Acceptance Criteria

  • request<T>() rejects on non-2xx HTTP statuses instead of returning them as successful ApiResponse<T> values
  • JSON and text error bodies are safely parsed and mapped into ApiError.message, details, requestId, and path where available
  • Existing error interceptors continue to run for normalized HTTP errors, including 401 and 429 responses
  • Timeout and network-error behavior remains compatible with the current normalizeError handling
  • Added validation notes/tests demonstrating 2xx success, 401 JSON error, 429 rate-limit error, 500 text error, and aborted request behavior

Test Coverage

  • 2xx success responses (200, 201)
  • 401 JSON error with parsed details and suggestion
  • 429 rate-limit error with retry info
  • 500 text error with plain text body
  • Aborted request (timeout) handling
  • Network error handling
  • Error interceptor chain execution
  • Response interceptor behavior for success vs error

Closes #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