Skip to content

Instantly share code, notes, and snippets.

@devotdev
Created May 15, 2026 13:04
Show Gist options
  • Select an option

  • Save devotdev/362f01df6cdee53a86d952a0137a754c to your computer and use it in GitHub Desktop.

Select an option

Save devotdev/362f01df6cdee53a86d952a0137a754c to your computer and use it in GitHub Desktop.
app/services/partner_api/application.rb
module PartnerApi
class Application
class NetTimeout < StandardError; end
include HTTParty
REQUEST_TIMEOUT = ENV.fetch('PARTNER_API_REQUEST_TIMEOUT', 15).to_i
OPEN_TIMEOUT = ENV.fetch('PARTNER_API_OPEN_TIMEOUT', 5).to_i
attr_reader :token
def initialize(token:, timeout: nil)
@token = token
@timeout = timeout || REQUEST_TIMEOUT
end
protected
def default_headers
{
Authorization: "Bearer #{token}",
Accept: 'application/json',
Connection: 'keep-alive'
}
end
def handle_timeout_exception
yield
rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout => e
Rails.logger.error("[PartnerApi] timeout: #{e.class} - #{e.message}")
raise NetTimeout
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment