fix: include error response body and status code in FalException#7
Open
otopba wants to merge 1 commit intofal-ai:mainfrom
Open
fix: include error response body and status code in FalException#7otopba wants to merge 1 commit intofal-ai:mainfrom
otopba wants to merge 1 commit intofal-ai:mainfrom
Conversation
Previously, responseToException() parsed the JSON error body but
discarded it, creating FalException with only "Request failed with
code: NNN". This lost valuable error details from the API (validation
messages, error descriptions, etc.).
Changes:
- Extract human-readable messages from common error response formats:
{"detail": [{"msg": "..."}]}, {"message": "..."}, {"error": "..."}
- Add statusCode and body fields to FalException for programmatic access
- Maintain full backward compatibility with existing constructors
- Add 23 unit tests covering all parsing paths and edge cases
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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
responseToException()inHttpClientparsed the JSON error body but silently discarded it, always creatingFalExceptionwith only"Request failed with code: NNN". This lost valuable error details returned by the fal.ai API.Before:
After:
Changes
FalException— addedstatusCode(int) andbody(String) fields with backward-compatible constructorsHttpClient.responseToException()— now reads the response body and extracts human-readable messages from common error formats:{"detail": [{"msg": "...", ...}]}— validation errors (messages joined with;){"detail": "..."}— string detail{"message": "..."}— generic error message{"error": "..."}— error stringHttpClient.extractDetailMessage()— safe JSON parsing with fallback (never throws)Backward Compatibility
FalExceptionconstructors preserved unchangedgetMessage()still starts with"Request failed with code: NNN"— detail is appended after": "-1/nullwhen using legacy constructorsclient-asyncorclient-kotlinmodules (they useHttpClientinternally)Test plan
client,client-async,client-kotlin) compile successfully🤖 Generated with Claude Code