fix: raise JSONError for malformed API error bodies instead of AssertionError - #462
Harsh23Kashyap wants to merge 1 commit into
Conversation
…ionError
handle_error_response validated the error payload with asserts, but the
except clause only caught KeyError/TypeError, so any error body that was
not {"error": {...}} - a FastAPI-style {"detail": ...} body, a plain
string error, or a non-dict JSON body - escaped as a raw AssertionError
instead of the intended error.JSONError. Replace the asserts with
explicit isinstance checks that raise JSONError.
Broly Security ScanWarning Latest baseline snapshot is stale. Broly is running in PR-only fallback mode until the next scheduled baseline refreshes. This does not block the PR. Note ✅ Clean scan Note Re-scan this PR anytime with
|
|
This repo is deprecated and is not taking new patches. Thanks. The new SDK is hosted at https://github.com/togethercomputer/together-py |
Have you read the Contributing Guidelines? Yes
Issue #460
Describe your changes
handle_error_responsevalidated the error payload with asserts, but theexceptonly caughtKeyError/TypeError, so any error body not shaped as{"error": {...}}- a FastAPI-style{"detail": ...}body, a plain string error, or a non-dict JSON body - escaped as a rawAssertionError(orAttributeErrorunderpython -O) and theJSONErrorfallback was dead code. The asserts are replaced with explicitisinstancechecks that raiseerror.JSONError.Adds
tests/unit/test_error_response_handling.pycovering the three malformed body shapes plus the valid 429/400 mappings. The new tests fail on unpatched code (AssertionError) and pass with this change; the full unit suite passes (210 passed).