Exception: RightSignature::ResponseError
- Inherits:
-
Exception
- Object
- Exception
- RightSignature::ResponseError
- Defined in:
- lib/rightsignature/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#code ⇒ Object
returns HTTP Code from response.
-
#common_solutions ⇒ Object
Suggestions on how to resolve a certain error.
-
#detailed_message ⇒ Object
Attempts to parse an error message from the response body.
-
#initialize(response, message = nil) ⇒ ResponseError
constructor
Creates new instance of RightSignature::ResponseError to make API calls * response: Net::HTTP response or HTTParty response * message: (Optional) Custom error message.
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, =nil) self.set_backtrace(caller[1..-1]) if self.backtrace.nil? @response = response super(( || @response.)) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/rightsignature/errors.rb', line 3 def response @response end |
Instance Method Details
#code ⇒ Object
returns HTTP Code from response
16 17 18 |
# File 'lib/rightsignature/errors.rb', line 16 def code @response.code end |
#common_solutions ⇒ Object
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_message ⇒ Object
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 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 |