Exception: FacebookCommerce::Api::UnexpectedHttpResponse

Inherits:
StandardError
  • Object
show all
Defined in:
lib/facebook_commerce.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ UnexpectedHttpResponse

Returns a new instance of UnexpectedHttpResponse.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/facebook_commerce.rb', line 24

def initialize(response)
  message = response.message || response.code
  
  # Try to extract error_user_msg from Facebook API response
  if response.body && !response.body.empty?
    begin
      parsed_body = JSON.parse(response.body)
      error_user_msg = parsed_body.dig('error', 'error_user_msg')
      if error_user_msg
        message = "#{message}: #{error_user_msg}"
      end
    rescue JSON::ParserError
      # If JSON parsing fails, just use the original message
    end
  end
  
  super message
end