class Koala::Facebook::APIError

Facebook responded with an error to an API request. If the exception contains a nil http_status, then the error was detected before making a call to Facebook. (e.g. missing access token)

Attributes

fb_error_code[RW]
fb_error_debug[RW]
fb_error_message[RW]
fb_error_rev[RW]
fb_error_subcode[RW]
fb_error_trace_id[RW]
fb_error_type[RW]
fb_error_user_msg[RW]
fb_error_user_title[RW]
http_status[RW]
response_body[RW]

Public Class Methods

new(http_status, response_body, error_info = nil) click to toggle source

Create a new API Error

@param http_status [Integer] The HTTP status code of the response @param response_body [String] The response body @param error_info One of the following:

[Hash] The error information extracted from the request
       ("type", "code", "error_subcode", "message")
[String] The error description
If error_info is nil or not provided, the method will attempt to extract
the error info from the response_body

@return the newly created APIError

Calls superclass method
   # File lib/koala/errors.rb
40 def initialize(http_status, response_body, error_info = nil)
41   if response_body
42     self.response_body = response_body.strip
43   else
44     self.response_body = ''
45   end
46   self.http_status = http_status
47 
48   if error_info && error_info.is_a?(String)
49     message = error_info
50   else
51     unless error_info
52       begin
53         error_info = JSON.parse(response_body)['error'] if response_body
54       rescue
55       end
56       error_info ||= {}
57     end
58 
59     self.fb_error_type = error_info["type"]
60     self.fb_error_code = error_info["code"]
61     self.fb_error_subcode = error_info["error_subcode"]
62     self.fb_error_message = error_info["message"]
63     self.fb_error_user_msg = error_info["error_user_msg"]
64     self.fb_error_user_title = error_info["error_user_title"]
65 
66     self.fb_error_trace_id = error_info["x-fb-trace-id"]
67     self.fb_error_debug = error_info["x-fb-debug"]
68     self.fb_error_rev = error_info["x-fb-rev"]
69 
70     error_array = []
71     %w(type code error_subcode message error_user_title error_user_msg x-fb-trace-id).each do |key|
72       error_array << "#{key}: #{error_info[key]}" if error_info[key]
73     end
74 
75     if error_array.empty?
76       message = self.response_body
77     else
78       message = error_array.join(', ')
79     end
80   end
81   message += " [HTTP #{http_status}]" if http_status
82 
83   super(message)
84 end