| 72 | } |
| 73 | |
| 74 | GenerateResult HttpRequestHandler::execute_single_request( |
| 75 | const std::string& path, |
| 76 | const httplib::Headers& headers, |
| 77 | const std::string& body, |
| 78 | const std::string& content_type) { |
| 79 | auto handler = [](const httplib::Result& res, |
| 80 | const std::string& protocol) -> GenerateResult { |
| 81 | if (!res) { |
| 82 | ai::logger::log_error("{} request failed - no response", protocol); |
| 83 | GenerateResult result("Network error: Failed to connect to API"); |
| 84 | result.is_retryable = true; // Network errors are retryable |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | ai::logger::log_debug("Got response: status={}, body_size={}", res->status, |
| 89 | res->body.size()); |
| 90 | |
| 91 | if (res->status == 200) { |
| 92 | GenerateResult result; |
| 93 | result.text = res->body; |
| 94 | result.finish_reason = kFinishReasonStop; // HTTP request succeeded |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | // For non-200 responses, return error with full body for parsing |
| 99 | GenerateResult error_result; |
| 100 | error_result.error = res->body; |
| 101 | error_result.finish_reason = kFinishReasonError; |
| 102 | error_result.provider_metadata = std::to_string(res->status); |
| 103 | error_result.is_retryable = is_status_code_retryable(res->status); |
| 104 | return error_result; |
| 105 | }; |
| 106 | |
| 107 | return make_request(path, headers, body, content_type, handler); |
| 108 | } |
| 109 | |
| 110 | GenerateResult HttpRequestHandler::make_request(const std::string& path, |
| 111 | const httplib::Headers& headers, |
nothing calls this directly
no test coverage detected