Exception: FbGraph2::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- FbGraph2::Exception
- Defined in:
- lib/fb_graph2/exception.rb
Direct Known Subclasses
Defined Under Namespace
Classes: BadRequest, InternalServerError, InvalidRequest, InvalidToken, NotFound, Unauthorized
Constant Summary collapse
- ERROR_HEADER_MATCHERS =
{ /not_found/ => NotFound, /invalid_token/ => InvalidToken, /invalid_request/ => InvalidRequest }
Instance Attribute Summary collapse
-
#code ⇒ Object
(also: #error_code)
Returns the value of attribute code.
-
#error_subcode ⇒ Object
Returns the value of attribute error_subcode.
-
#status ⇒ Object
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .detect(status, body = {}, headers = {}) ⇒ Object
- .detect_from_header(headers, error) ⇒ Object
- .detect_from_status(status) ⇒ Object
Instance Method Summary collapse
-
#initialize(status, message, error = {}) ⇒ Exception
constructor
A new instance of Exception.
Constructor Details
#initialize(status, message, error = {}) ⇒ Exception
Returns a new instance of Exception.
42 43 44 45 46 47 48 |
# File 'lib/fb_graph2/exception.rb', line 42 def initialize(status, , error = {}) super self.status = status self.type = error[:type] self.code = error[:code] self.error_subcode = error[:error_subcode] end |
Instance Attribute Details
#code ⇒ Object Also known as: error_code
Returns the value of attribute code.
3 4 5 |
# File 'lib/fb_graph2/exception.rb', line 3 def code @code end |
#error_subcode ⇒ Object
Returns the value of attribute error_subcode.
3 4 5 |
# File 'lib/fb_graph2/exception.rb', line 3 def error_subcode @error_subcode end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/fb_graph2/exception.rb', line 3 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/fb_graph2/exception.rb', line 3 def type @type end |
Class Method Details
.detect(status, body = {}, headers = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fb_graph2/exception.rb', line 7 def detect(status, body = {}, headers = {}) error = body[:error] = error.try(:[], :message) klass = detect_from_header(headers, error) || detect_from_status(status) if klass klass.new , error else new status, , error end end |
.detect_from_header(headers, error) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/fb_graph2/exception.rb', line 31 def detect_from_header(headers, error) key, value = headers.detect do |name, value| name.upcase == "WWW-Authenticate".upcase end || return matched, klass = ERROR_HEADER_MATCHERS.detect do |matcher, klass_name| matcher =~ value end || return klass end |
.detect_from_status(status) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fb_graph2/exception.rb', line 18 def detect_from_status(status) case status when 400 BadRequest when 401 Unauthorized when 404 NotFound when 500 InternalServerError end end |