Class: Sumologic::Http::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic/http/response_handler.rb

Overview

Handles HTTP response parsing and error handling

Instance Method Summary collapse

Instance Method Details

#extract_rate_limit_info(response) ⇒ Object

Extract rate limit info from response headers



32
33
34
35
36
37
38
39
# File 'lib/sumologic/http/response_handler.rb', line 32

def extract_rate_limit_info(response)
  {
    retry_after: parse_retry_after(response),
    limit: response['X-RateLimit-Limit']&.to_i,
    remaining: response['X-RateLimit-Remaining']&.to_i,
    reset_at: parse_reset_time(response)
  }
end

#handle(response) ⇒ Object

Parse response and handle errors



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sumologic/http/response_handler.rb', line 10

def handle(response)
  case response.code.to_i
  when 200..299
    parse_success(response)
  when 401, 403
    handle_authentication_error(response)
  when 429
    handle_rate_limit_error(response)
  when 500..599
    handle_server_error(response)
  else
    handle_generic_error(response)
  end
end

#retryable?(response) ⇒ Boolean

Check if response indicates a retryable error

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/sumologic/http/response_handler.rb', line 26

def retryable?(response)
  code = response.code.to_i
  code == 429 || code.between?(500, 599)
end