class ActiveGenie::Clients::BaseClient
def execute_request(uri, request, headers, config)
-
(Hash, nil)
- The parsed JSON response or nil if empty
Parameters:
-
config
(Hash
) -- Configuration options -
headers
(Hash
) -- Additional headers to include -
request
(Net::HTTP::Request
) -- The request object -
uri
(URI
) -- The URI for the request
def execute_request(uri, request, headers, config) start_time = Time.now # Apply headers apply_headers(request, headers) # Apply retry logic retry_with_backoff(config) do http = create_http_client(uri, config) begin response = http.request(request) # Handle common HTTP errors case response when Net::HTTPSuccess parsed_response = parse_response(response) # Log request details if logging is enabled log_request_details( uri: uri, method: request.method, status: response.code, duration: Time.now - start_time, response: parsed_response ) parsed_response when Net::HTTPTooManyRequests raise RateLimitError, "Rate limit exceeded: #{response.body}" when Net::HTTPClientError, Net::HTTPServerError raise ClientError, "HTTP Error #{response.code}: #{response.body}" else raise ClientError, "Unexpected response: #{response.code} - #{response.body}" end rescue Timeout::Error, Errno::ETIMEDOUT raise TimeoutError, "Request to #{uri} timed out" rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, SocketError => e raise NetworkError, "Network error: #{e.message}" end end end