openai-php / client

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

Make ErrorException return types nullable #85

Closed nurdism closed 1 year ago

nurdism commented 1 year ago

ErrorException will throw a TypeError when attempting to use getErrorCode() or getErrorType() if they are null, this RP makes those function return nullable strings

gehrisandro commented 1 year ago

Hi @nurdism

Could you please provide an example, when the code or type is empty?

nurdism commented 1 year ago

I am unsure about getErrorCode() because I couldn't find much documentation on exactly what comes back in the response, added it to be safer. But as far as getErrorType() 429 - You exceeded your current quota, please check your plan and billing details does not have a type and will throw a type error when attempting to use getErrorType()

gehrisandro commented 1 year ago

@nurdism Than I suggest to only make the type nullable. Can you please adjust your PR?

gehrisandro commented 1 year ago

Oh, I just saw that in another issue we have an error response where the code is null: https://github.com/openai-php/client/pull/89#discussion_r1148437425

So both should be nullable.

Please add some tests as @nunomaduro mentioned above and then the PR should be ready. If you have troubles doing so, please let me know.

nurdism commented 1 year ago

I don't even know where to begin to write a test for this, feel free to close this and submit a different PR

gehrisandro commented 1 year ago

Okay, no worries. I will do it later this week.

gehrisandro commented 1 year ago

Finally found time to fix this https://github.com/openai-php/client/pull/102