Exception: Improvmx::CommunicationError

Inherits:
Error
  • Object
show all
Defined in:
lib/improvmx/exceptions/exceptions.rb

Overview

Public: Class for managing communications (eg http) response errors

Instance Attribute Summary collapse

Attributes inherited from Error

#object

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, response = nil) ⇒ CommunicationError

Public: initialization of new error given a message and/or object

message - a String detailing the error response - a RestClient::Response object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/improvmx/exceptions/exceptions.rb', line 24

def initialize(message = nil, response = nil)
  @response = response
  @code = response.code

  json = JSON.parse(response.body)
  api_message = json['error'] || json['errors']

  message ||= ''
  message = "#{message} #{api_message}"

  super(message, response)
rescue NoMethodError, JSON::ParserError
  super(message, response)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



17
18
19
# File 'lib/improvmx/exceptions/exceptions.rb', line 17

def code
  @code
end