DEV: Log error responses on Gemini / Cloudflare embeddings requests (#736)

This commit is contained in:
Rafael dos Santos Silva 2024-08-01 17:25:24 -03:00 committed by GitHub
parent 9d887ad4ac
commit 7dc0a2a20a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View File

@ -19,7 +19,17 @@ module ::DiscourseAi
raise Net::HTTPBadResponse if ![200].include?(response.status)
case response.status
when 200
JSON.parse(response.body, symbolize_names: true)
when 429
# TODO add a AdminDashboard Problem?
else
Rails.logger.warn(
"Cloudflare Workers AI Embeddings failed with status: #{response.status} body: #{response.body}",
)
raise Net::HTTPBadResponse
end
end
end
end

View File

@ -14,9 +14,17 @@ module ::DiscourseAi
conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
response = conn.post(url, body.to_json, headers)
raise Net::HTTPBadResponse if ![200].include?(response.status)
case response.status
when 200
JSON.parse(response.body, symbolize_names: true)
when 429
# TODO add a AdminDashboard Problem?
else
Rails.logger.warn(
"Google Gemini Embeddings failed with status: #{response.status} body: #{response.body}",
)
raise Net::HTTPBadResponse
end
end
end
end