Skip to content

Handle OpenAI API errors in processChatResult#540

Merged
ilvalerione merged 5 commits intoneuron-core:3.xfrom
viicslen:patch-1
Apr 14, 2026
Merged

Handle OpenAI API errors in processChatResult#540
ilvalerione merged 5 commits intoneuron-core:3.xfrom
viicslen:patch-1

Conversation

@viicslen
Copy link
Copy Markdown
Contributor

This pull request adds improved error handling to the processChatResult method in src/Providers/OpenAI/Responses/HandleChat.php. The main change is to ensure that errors returned from the OpenAI API are detected and reported clearly, making debugging and maintenance easier.

Error handling improvements:

  • Added a check for an 'error' key in the $result array, throwing a ProviderException with the error message if present.
  • Added a check to ensure the 'output' key exists in the $result array, throwing a ProviderException if it is missing.

@ilvalerione
Copy link
Copy Markdown
Contributor

ilvalerione commented Apr 11, 2026

the "empty output" is not necessary on error. I don't think it should raise an exception. It could depends by the stop reason for example.

@viicslen
Copy link
Copy Markdown
Contributor Author

@ilvalerione As I’m not too familiar with the response structure, I have updated the checks to include only what is necessary for the existing array_filter($result['output'], ...) to work. This prevents a TypeError from being thrown when the first parameter is null instead of an array, which is currently happening in some instances.

Alternatively, would it be better to use the null coalescing operator ($result['output'] ?? []) instead?

@ilvalerione ilvalerione merged commit 7209912 into neuron-core:3.x Apr 14, 2026
11 of 12 checks passed
@viicslen viicslen deleted the patch-1 branch April 14, 2026 12:55
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