Skip to content

Conversation

iBotPeaches
Copy link
Collaborator

What:

  • Bug Fix
  • New Feature

Description:

The error object can be an array or a string. In MCP it can even be double nested error objects. Don't worry engineers of all companies - even the big guys have bugs.

So we need to support

{
  "error": {
    "message": "The model `gpt-42` does not exist",
    "type": "invalid_request_error",
    "param": null,
    "code": 123
  }
}

OR

{
  "error": "You have insufficient permissions for this operation. Missing scopes: api.model.read. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Viewer, Member, Owner), and if you're using a restricted API key, that it has the necessary scopes."
}

This code changes every few months when a structure it assumed was false. So now it will take a string on error or an object and won't crash on any missing keys.

Related:

fixes: #681

@iBotPeaches iBotPeaches changed the title fix(OpenAI): handle data.error and data.error.error fix(OpenAI): have a robust ErrorException to handle object/string error responses. Sep 11, 2025
@iBotPeaches iBotPeaches requested a review from Copilot September 12, 2025 10:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the ErrorException handling to robustly support both string and object error responses from the OpenAI API. The changes ensure the exception handler can process error responses that are either simple string messages or structured objects with message, type, and code fields.

  • Updates ErrorException constructor to accept both string and array error formats
  • Adds null-safe access to optional error object properties (type, code)
  • Includes comprehensive test coverage for the new error handling scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Exceptions/ErrorException.php Modified constructor to handle string/array error formats and added null-safe property access
src/Transporters/HttpTransporter.php Updated type annotation to reflect that error can be string or array
tests/Transporters/HttpTransporter.php Added test cases for string errors and partial error objects

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@iBotPeaches iBotPeaches added this to the v0.17.0 milestone Sep 12, 2025
@iBotPeaches iBotPeaches merged commit 6c8d610 into main Sep 12, 2025
24 checks passed
@iBotPeaches iBotPeaches deleted the issue-681 branch September 24, 2025 10:35
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.

[Bug]: Contents must be of type array, string given in HttpTransporter

1 participant