Module: RubyApiPackCore::Handlers::ResponseValidator

Defined in:
lib/ruby_api_pack_core/handlers/response_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_response(response, expected_type: :any) ⇒ Object



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

def validate_response(response, expected_type: :any)
  case expected_type
  when :array
    raise "Expected an Array, got #{response.class}: #{response.inspect}" unless response.is_a?(Array)
  when :hash
    raise "Expected a Hash, got #{response.class}: #{response.inspect}" unless response.is_a?(Hash)
  end

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