Created
May 15, 2026 13:04
-
-
Save devotdev/362f01df6cdee53a86d952a0137a754c to your computer and use it in GitHub Desktop.
app/services/partner_api/application.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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