| 43 | } |
| 44 | |
| 45 | GenerateResult HttpRequestHandler::post(const std::string& path, |
| 46 | const httplib::Headers& headers, |
| 47 | const std::string& body, |
| 48 | const std::string& content_type) { |
| 49 | // Create a retry policy with the configured settings |
| 50 | retry::RetryPolicy retry_policy(config_.retry_config); |
| 51 | |
| 52 | // Define the function to execute with retry |
| 53 | auto execute_request = [this, &path, &headers, &body, |
| 54 | &content_type]() -> GenerateResult { |
| 55 | return execute_single_request(path, headers, body, content_type); |
| 56 | }; |
| 57 | |
| 58 | // Define the function to check if a result is retryable |
| 59 | std::function<bool(const GenerateResult&)> is_retryable = |
| 60 | [](const GenerateResult& result) -> bool { |
| 61 | return result.is_retryable.value_or(false); |
| 62 | }; |
| 63 | |
| 64 | try { |
| 65 | return retry_policy.execute_with_retry(execute_request, is_retryable); |
| 66 | } catch (const retry::RetryError& e) { |
| 67 | ai::logger::log_error("Request failed after retries: {}", e.what()); |
| 68 | GenerateResult error_result(e.what()); |
| 69 | error_result.is_retryable = false; // Already retried |
| 70 | return error_result; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | GenerateResult HttpRequestHandler::execute_single_request( |
| 75 | const std::string& path, |
no test coverage detected