class RightSignature::ResponseError

Attributes

response[R]

Public Class Methods

new(response, message=nil) click to toggle source

Creates new instance of RightSignature::ResponseError to make API calls

  • response: Net::HTTP response or HTTParty response

  • message: (Optional) Custom error message

Calls superclass method
# File lib/rightsignature/errors.rb, line 9
def initialize(response, message=nil)
  self.set_backtrace(caller[1..-1]) if self.backtrace.nil?
  @response = response
  super((message || @response.message))
end

Public Instance Methods

code() click to toggle source

returns HTTP Code from response

# File lib/rightsignature/errors.rb, line 16
def code
  @response.code
end
common_solutions() click to toggle source

Suggestions on how to resolve a certain error

# File lib/rightsignature/errors.rb, line 21
def common_solutions
  if @response.code.to_i == 406
    "Check the Content-Type and makes sure it's the correct type (usually application/json or application/xml), ensure url has .xml or .json at the end, check 'Accept' header to allow xml or json ('*/*' for anything)"
  elsif @response.code.to_i  == 401
    "Check your credentials and make sure they are correct and not expired"
  elsif @response.code.to_i  >= 500 && @response.code.to_i  < 600
    "Check the format of your xml or json"
  end
end
detailed_message() click to toggle source

Attempts to parse an error message from the response body

# File lib/rightsignature/errors.rb, line 32
def detailed_message
  if @response.is_a? Net::HTTPResponse
    parsed_response = MultiXml.parse(@response.body)

    parsed_response["error"]["message"] if parsed_response && parsed_response["error"]
  else
    if @response.parsed_response.is_a? Hash
      @response.parsed_response["error"]["message"] if @response.parsed_response["error"]
    end
  end
end