Module: RubyApiPackCloudways::Handlers::ResponseValidator

Included in:
Api::CwLists
Defined in:
lib/ruby_api_pack_cloudways/handlers/response_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_response(response, expected_key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ruby_api_pack_cloudways/handlers/response_validator.rb', line 6

def validate_response(response, expected_key)
  raise "Unexpected response format: #{response.inspect}" unless response.is_a?(Hash) && response.key?(expected_key)

  result = response[expected_key]
  raise "Expected '#{expected_key}' to be an Array, got #{result.class}: #{result.inspect}" unless result.is_a?(Array)

  result
rescue StandardError => e
  log_error("Error validating response: #{e.message}")
  raise "An error occurred while processing the response: #{e.message}"
end