class SocialPlus::WebApi::ApiError

An Exception class which wraps errors from SocialPlus Web API

Constants

EXCEPTION_CLASSES

Attributes

code[R]

@return [Integer] the error code (API error code or HTTP status)

Public Class Methods

exception_from_api_result(response, result) click to toggle source
# File lib/social_plus/web_api/api_error.rb, line 30
def self.exception_from_api_result(response, result)
  if social_plus_error?(response, result)
    error = result['error']
    raise EXCEPTION_CLASSES[error['code']], error
  else
    raise HttpResponseError, response
  end
end
new(error) click to toggle source

@overload initialize(error)

@param error [Hash] a Hash which represents an API error
@option error [String] message the error message
@option error [Integer] code the error code
Calls superclass method
# File lib/social_plus/web_api/api_error.rb, line 13
def initialize(error)
  super(error['message'])
  @code = error['code']
end

Private Class Methods

social_plus_error?(response, result) click to toggle source
# File lib/social_plus/web_api/api_error.rb, line 40
def self.social_plus_error?(response, result)
  case response
  when Net::HTTPServerError, Net::HTTPClientError
    result.key?('error') && %w(message code).all? { |key| result['error'].key?(key) }
  else
    false
  end
end