Skip to content

fix: preserve non-object response error bodies#690

Open
lin-hongkuan wants to merge 1 commit into
ollama:mainfrom
lin-hongkuan:codex/response-error-json-nonobject
Open

fix: preserve non-object response error bodies#690
lin-hongkuan wants to merge 1 commit into
ollama:mainfrom
lin-hongkuan:codex/response-error-json-nonobject

Conversation

@lin-hongkuan

Copy link
Copy Markdown

Summary

  • Only read the error field from JSON object error responses.
  • Preserve non-object JSON error bodies instead of raising a constructor-time exception.

Why

ResponseError currently assumes any decoded JSON response is a dictionary. JSON strings, arrays, or numbers are valid response bodies and should still produce a useful ResponseError.

Testing

  • python -m pytest tests/test_type_serialization.py::test_response_error_uses_json_object_error_field tests/test_type_serialization.py::test_response_error_preserves_non_object_json_body -q
  • git diff --check

@vaderollama vaderollama left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — guards against non-dict JSON error bodies in ResponseError.__init__. Previously json.loads(error).get('error', error) would crash if the response body was a JSON string, array, or number. The isinstance(parsed_error, dict) check is the right fix. Tests cover both dict and non-dict cases.

@ParthSareen — ready to merge.

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.

2 participants