class Sitejabber::ErrorChecker
Attributes
body[R]
headers[R]
http_status[R]
Public Class Methods
new(http_status, body, headers)
click to toggle source
# File lib/sitejabber/error_checker.rb, line 5 def initialize http_status, body, headers @http_status = http_status.to_i @body = body @headers = headers end
Public Instance Methods
error_if_appropriate()
click to toggle source
# File lib/sitejabber/error_checker.rb, line 11 def error_if_appropriate if http_status >= 500 ServerError.new http_status, body elsif http_status >= 400 ClientError.new http_status, body elsif http_status >= 300 ServerError.new http_status, body elsif response_hash[ "errorCode" ] error_class.new http_status, body, error_info end end
Protected Instance Methods
error_class()
click to toggle source
# File lib/sitejabber/error_checker.rb, line 25 def error_class code = response_hash[ "errorCode" ].to_i if code < 200 OAuthTokenRequestError elsif code < 300 AuthenticationError elsif code < 429 ClientError elsif code == 429 RateLimitError else APIError end end
error_info()
click to toggle source
# File lib/sitejabber/error_checker.rb, line 41 def error_info response_hash.slice "errorCode", "errorReason" end
response_hash()
click to toggle source
# File lib/sitejabber/error_checker.rb, line 45 def response_hash @response_hash ||= begin JSON.parse body rescue JSON::ParserError {} end end