openai-php / client

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

HTTP status in ErrorException #487

Closed GuidoBelluomo closed 1 week ago

GuidoBelluomo commented 1 month ago

What:

Description:

I've added the HTTP status code to ErrorException, so it's possible to ignore 404 errors for deleting files that don't exist, if desired. OpenAI doesn't provide an exhaustive enough error response for missing files that I can just quickly and universally check:

{
  "error": {
    "message": "No such File object: file-testFile",
    "type": "invalid_request_error",
    "param": "id",
    "code": null
  }
}

As you can see there's no easy error code for missing resources, parsing the message is a terrible idea, so exposing the HTTP status code (404 in this case) enables to perform such simple checks.

gehrisandro commented 1 week ago

Hi @GuidoBelluomo

Thanks for you PR!