Skip to content

Provide a clearer JsonException message when HttpTransporter receives invalid response.#766

Open
arbazargani wants to merge 1 commit intoopenai-php:mainfrom
arbazargani:main
Open

Provide a clearer JsonException message when HttpTransporter receives invalid response.#766
arbazargani wants to merge 1 commit intoopenai-php:mainfrom
arbazargani:main

Conversation

@arbazargani
Copy link
Copy Markdown

Fix handling of invalid response.

What:

  • Bug Fix
  • New Feature

Description:

This PR improves the error handling in HttpTransporter when an invalid or malformed response is returned by the service provider.

Previously, such cases could result in unclear or misleading exceptions. In scenarios where the service provider returned a non-JSON response (such as an HTML error page like 403 Forbidden from nginx, or a CDN-blocked request), the client would typically throw a generic syntax error, which made it difficult to understand the root cause.

This change ensures that a proper JsonException is thrown with a more descriptive and accurate error message, making debugging easier and behavior more predictable. It explicitly handles cases where the response body is not valid JSON and provides clearer insight into what actually went wrong.

Related:

N/A

@iBotPeaches
Copy link
Copy Markdown
Collaborator

At the moment not really feeling the use for this. The JsonException is clear that we got an issue. Other classes tend to catch different 5xx and 4xx errors. This just adds noise and confusion to an exception.

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