Exception: LeadRouter::Exception

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/lead_router/exceptions.rb

Overview

All possible exceptions raised by the LeadRouter::Client will be an instance of this class

Use ‘original_exception’ method to access the original exception object , or just ‘to_s’ to display a nice error message

If the error was an invalid HTTP status code, ‘http_code’ and ‘http_body’ methods will be available (they return 0 and “” otherwise)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ Exception

Returns a new instance of Exception.



15
16
17
# File 'lib/lead_router/exceptions.rb', line 15

def initialize(exception)
  @original_exception = exception
end

Instance Attribute Details

#original_exceptionObject

Returns the value of attribute original_exception.



13
14
15
# File 'lib/lead_router/exceptions.rb', line 13

def original_exception
  @original_exception
end

Instance Method Details

#http_bodyObject



28
29
30
# File 'lib/lead_router/exceptions.rb', line 28

def http_body
  original_exception.respond_to?(:http_body) ? original_exception.http_body : ""
end

#http_codeObject



24
25
26
# File 'lib/lead_router/exceptions.rb', line 24

def http_code
  original_exception.respond_to?(:http_code) ? original_exception.http_code : 0
end

#to_sObject



19
20
21
22
# File 'lib/lead_router/exceptions.rb', line 19

def to_s
  return "#{original_exception.to_s}: HTTP status #{http_code} with body #{http_body}" unless http_code == 0
  original_exception.to_s
end