openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.75k stars 491 forks source link

Exception handling fails if message is an array #146

Closed gehrisandro closed 1 year ago

gehrisandro commented 1 year ago

Under some circumstances the API returns an error with an array of messages (even if the documentation says it's always a string).

array:4 [
  "message" => array:1 [
    0 => "Invalid schema for function 'domains': In context=('properties', 'domains'), array schema missing items"
  ]
  "type" => "invalid_request_error"
  "param" => null
  "code" => null
]
prismosoft commented 1 year ago

Yep, same here.

This needs to be fixed in: https://github.com/openai-php/client/blob/67937756931af848c03112e52706aa6ad175aa7a/src/Exceptions/ErrorException.php#L18

Should be replaced by: parent::__construct(json_encode($contents['message']));