fix: Handle OpenAI API errors (#9560)
This commit is contained in:
@@ -77,8 +77,12 @@ class Integrations::OpenaiBaseService
|
||||
response = HTTParty.post(API_URL, headers: headers, body: body)
|
||||
Rails.logger.info("OpenAI API response: #{response.body}")
|
||||
|
||||
return { error: response.parsed_response, error_code: response.code } unless response.success?
|
||||
|
||||
choices = JSON.parse(response.body)['choices']
|
||||
|
||||
choices.present? ? choices.first['message']['content'] : nil
|
||||
return { message: choices.first['message']['content'] } if choices.present?
|
||||
|
||||
{ message: nil }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user