class FbGraph2::Exception
Constants
- ERROR_HEADER_MATCHERS
Attributes
code[RW]
error_code[RW]
error_subcode[RW]
status[RW]
type[RW]
Public Class Methods
detect(status, body = {}, headers = {})
click to toggle source
# File lib/fb_graph2/exception.rb, line 7 def detect(status, body = {}, headers = {}) error = body[:error] message = error.try(:[], :message) klass = detect_from_header(headers, error) || detect_from_status(status) if klass klass.new message, error else new status, message, error end end
detect_from_header(headers, error)
click to toggle source
# 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)
click to toggle source
# 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
new(status, message, error = {})
click to toggle source
Calls superclass method
# File lib/fb_graph2/exception.rb, line 42 def initialize(status, message, error = {}) super message self.status = status self.type = error[:type] self.code = error[:code] self.error_subcode = error[:error_subcode] end