swift-eventsource icon indicating copy to clipboard operation
swift-eventsource copied to clipboard

Get response data when the status is not in 200-300

Open noobnooc opened this issue 1 year ago • 3 comments

I used this package to access the OpenAI API. However, when the response has a status code outside of the range 200-300, an error occurs. The UnsuccessfulResponseError object only includes a responseStatus field, but OpenAI responded with a JSON error message like the following:

{
  "error": {
    "param": null,
    "message": "Rate limit reached for default-gpt-3.5-turbo in organization org-xxx on requests per minute. Limit: 20 / min. Current: 30 / min. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https:\/\/platform.openai.com\/account\/billing to add a payment method.",
    "code": null,
    "type": "requests"
  }
}

I would like to retrieve the message from this error response, but I couldn't find a way to do it. Is it possible to do so with the current version? If not, could you please add this functionality in a future release?

noobnooc avatar Mar 09 '23 11:03 noobnooc