Exception: FbGraph::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- FbGraph::Exception
- Defined in:
- lib/fb_graph/exception.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_subcode ⇒ Object
Returns the value of attribute error_subcode.
-
#status ⇒ Object
(also: #code)
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .handle_response(status, message, details = {}) ⇒ Object
- .handle_structured_response(status, details, headers) ⇒ Object
- .klass_for_header(headers, error) ⇒ Object
- .klass_for_status(status) ⇒ Object
- .klass_for_structured_body(error) ⇒ Object
Instance Method Summary collapse
-
#initialize(status, message, details = {}) ⇒ Exception
constructor
A new instance of Exception.
Constructor Details
#initialize(status, message, details = {}) ⇒ Exception
Returns a new instance of Exception.
72 73 74 75 76 77 78 79 80 |
# File 'lib/fb_graph/exception.rb', line 72 def initialize(status, , details = {}) @status = status if (error = details.try(:[], :error)) @type = error[:type] @error_code = error[:code] @error_subcode = error[:error_subcode] end super end |
Instance Attribute Details
#error_code ⇒ Object
Returns the value of attribute error_code.
3 4 5 |
# File 'lib/fb_graph/exception.rb', line 3 def error_code @error_code end |
#error_subcode ⇒ Object
Returns the value of attribute error_subcode.
3 4 5 |
# File 'lib/fb_graph/exception.rb', line 3 def error_subcode @error_subcode end |
#status ⇒ Object Also known as: code
Returns the value of attribute status.
3 4 5 |
# File 'lib/fb_graph/exception.rb', line 3 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/fb_graph/exception.rb', line 3 def type @type end |
Class Method Details
.handle_response(status, message, details = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/fb_graph/exception.rb', line 22 def handle_response(status, , details = {}) klass = klass_for_status status exception = if klass klass.new , details else Exception.new status, , details end raise exception end |
.handle_structured_response(status, details, headers) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fb_graph/exception.rb', line 7 def handle_structured_response(status, details, headers) if (error = details[:error]) klass = klass_for_header(headers, error) || klass_for_structured_body(error) = [error[:type], error[:message]].join(' :: ') if klass raise klass.new(, details) else handle_response status, , details end else = [details[:error_code], details[:error_msg]].compact.join(' :: ') handle_response status, , details end end |
.klass_for_header(headers, error) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fb_graph/exception.rb', line 45 def klass_for_header(headers, error) key, value = headers.detect do |name, value| name.upcase == "WWW-Authenticate".upcase end || return if value =~ /invalid_token/ && error[:message] =~ /session has been invalidated/ InvalidSession else matched, klass = ERROR_HEADER_MATCHERS.detect do |matcher, klass_name| matcher =~ value end || return klass end end |
.klass_for_status(status) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fb_graph/exception.rb', line 32 def klass_for_status(status) case status when 400 BadRequest when 401 Unauthorized when 404 NotFound when 500 InternalServerError end end |
.klass_for_structured_body(error) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fb_graph/exception.rb', line 59 def klass_for_structured_body(error) case error[:type] when /OAuth/ Unauthorized else matched, klass = ERROR_EXCEPTION_MATCHERS.detect do |matcher, klass_name| matcher =~ error[:message] end || return klass end end |