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
Returns the value of attribute code.
-
#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.
41 42 43 44 45 46 |
# File 'lib/fb_graph2/exception.rb', line 41 def initialize(status, , error = {}) super self.status = status self.type = error[:type] self.code = error[:code] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/fb_graph2/exception.rb', line 3 def code @code 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
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fb_graph2/exception.rb', line 6 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
30 31 32 33 34 35 36 37 38 |
# File 'lib/fb_graph2/exception.rb', line 30 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
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fb_graph2/exception.rb', line 17 def detect_from_status(status) case status when 400 BadRequest when 401 when 404 NotFound when 500 InternalServerError end end |