Exception: TravelTime::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/travel_time/error.rb

Overview

The Error class wraps exceptions and provide useful information.

Constant Summary collapse

DEFAULT_MESSAGE =
'Error while processing the request'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, response: nil, exception: nil) ⇒ Error

Returns a new instance of Error.



10
11
12
13
14
15
# File 'lib/travel_time/error.rb', line 10

def initialize(message = nil, response: nil, exception: nil)
  @response = response
  @wrapped_exception = exception
  exc = super(parse_message(message))
  exc.set_backtrace(exception.backtrace) unless exception.nil?
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/travel_time/error.rb', line 8

def response
  @response
end

#wrapped_exceptionObject (readonly)

Returns the value of attribute wrapped_exception.



8
9
10
# File 'lib/travel_time/error.rb', line 8

def wrapped_exception
  @wrapped_exception
end

Instance Method Details

#additional_infoObject



29
30
31
# File 'lib/travel_time/error.rb', line 29

def additional_info
  extract_from_body('additional_info')
end

#descriptionObject



21
22
23
# File 'lib/travel_time/error.rb', line 21

def description
  extract_from_body('description')
end


33
34
35
# File 'lib/travel_time/error.rb', line 33

def documentation_link
  extract_from_body('documentation_link')
end

#error_codeObject



25
26
27
# File 'lib/travel_time/error.rb', line 25

def error_code
  extract_from_body('error_code')
end

#parse_message(message) ⇒ Object



17
18
19
# File 'lib/travel_time/error.rb', line 17

def parse_message(message)
  message || wrapped_exception&.message || description || DEFAULT_MESSAGE
end