Exception: Koala::Facebook::APIError
- Inherits:
-
KoalaError
- Object
- StandardError
- KoalaError
- Koala::Facebook::APIError
- Defined in:
- lib/koala/errors.rb
Overview
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)
Direct Known Subclasses
BadFacebookResponse, ClientError, OAuthTokenRequestError, ServerError
Instance Attribute Summary collapse
-
#fb_error_code ⇒ Object
Returns the value of attribute fb_error_code.
-
#fb_error_message ⇒ Object
Returns the value of attribute fb_error_message.
-
#fb_error_subcode ⇒ Object
Returns the value of attribute fb_error_subcode.
-
#fb_error_type ⇒ Object
Returns the value of attribute fb_error_type.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
Instance Method Summary collapse
-
#initialize(http_status, response_body, error_info = nil) ⇒ Object
constructor
Create a new API Error.
Constructor Details
#initialize(http_status, response_body, error_info = nil) ⇒ Object
Create a new API Error
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/koala/errors.rb', line 28 def initialize(http_status, response_body, error_info = nil) if response_body self.response_body = response_body.strip else self.response_body = '' end self.http_status = http_status if error_info && error_info.is_a?(String) = error_info else unless error_info begin error_info = MultiJson.load(response_body)['error'] if response_body rescue end error_info ||= {} end self.fb_error_type = error_info["type"] self.fb_error_code = error_info["code"] self.fb_error_subcode = error_info["error_subcode"] self. = error_info["message"] error_array = [] %w(type code error_subcode message).each do |key| error_array << "#{key}: #{error_info[key]}" if error_info[key] end if error_array.empty? = self.response_body else = error_array.join(', ') end end += " [HTTP #{http_status}]" if http_status super() end |
Instance Attribute Details
#fb_error_code ⇒ Object
Returns the value of attribute fb_error_code.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def fb_error_code @fb_error_code end |
#fb_error_message ⇒ Object
Returns the value of attribute fb_error_message.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def @fb_error_message end |
#fb_error_subcode ⇒ Object
Returns the value of attribute fb_error_subcode.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def fb_error_subcode @fb_error_subcode end |
#fb_error_type ⇒ Object
Returns the value of attribute fb_error_type.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def fb_error_type @fb_error_type end |
#http_status ⇒ Object
Returns the value of attribute http_status.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def http_status @http_status end |
#response_body ⇒ Object
Returns the value of attribute response_body.
13 14 15 |
# File 'lib/koala/errors.rb', line 13 def response_body @response_body end |