require 'real_page/validator' require 'real_page/utils/snowflake_event_tracker' module RealPage module Validator # Ensure there is no 'Fault' node in the response body class RequestFault # @param response [Hash] the XML response parsed into a # Hash def initialize(response, request_params = nil, request_name = nil) @response = response @request_params = request_params @request_name = request_name end # @raise [RealPage::Error::RequestFault] if the response has a fault def validate! return unless error? send_error_to_snowflake raise Error::RequestFault.new(error_message, fault_code, details) end private attr_reader :response, :request_params, :request_name def fault response['s:Envelope']['s:Body']['s:Fault'] end def details return unless fault['detail'] app_fault = fault['detail']['RPXApplicationFault'] Error::RequestFault::Details.new( custom_message: app_fault['CustomMessage'], exception_message: app_fault['ExceptionMessage'], log_id: app_fault['LogId'] ) end def error? !fault.nil? end def fault_code return unless fault code = fault['faultcode'] code = code['__content__'] if code.is_a?(Hash) code.strip end def error_message fault['faultstring']['__content__'] if fault end def send_error_to_snowflake case request_name when 'GetLeasesByTrafficSource' send_move_in_report_error_to_snowflake when 'ProspectSearch' send_prospect_search_error_to_snowflake end end def send_move_in_report_error_to_snowflake Utils::SnowflakeEventTracker.track_pms_resident_event( import_resident_id: request_params[:import_id] || '', api_name: request_name, resident_type: 'PRIMARY', request_params: request_params, phones_count: 0, error: error_message ) end def send_prospect_search_error_to_snowflake send_roommate_error_to_snowflake send_prospect_error_to_snowflake end def send_roommate_error_to_snowflake Utils::SnowflakeEventTracker.track_pms_resident_event( import_resident_id: request_params[:import_id] || '', api_name: request_name, resident_type: 'ROOMMATE', request_params: request_params, phones_count: 0, error: error_message ) end def send_prospect_error_to_snowflake Utils::SnowflakeEventTracker.track_pms_prospect_event( resident_type: 'PRIMARY', request_params: request_params, error: error_message ) end end end end