Exception: RightSignature::ResponseError

Inherits:
Exception
  • Object
show all
Defined in:
lib/rightsignature/errors.rb

Direct Known Subclasses

OAuthResponseError, TokenResponseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, message = nil) ⇒ ResponseError

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

  • response: Net::HTTP response or HTTParty response

  • message: (Optional) Custom error message



9
10
11
12
13
# 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

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/rightsignature/errors.rb', line 3

def response
  @response
end

Instance Method Details

#codeObject

returns HTTP Code from response



16
17
18
# File 'lib/rightsignature/errors.rb', line 16

def code
  @response.code
end

#common_solutionsObject

Suggestions on how to resolve a certain error



21
22
23
24
25
26
27
28
29
# 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_messageObject

Attempts to parse an error message from the response body



32
33
34
35
36
37
38
39
40
41
42
# 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