Exception: KahunaClient::Error

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

Overview

Custom error class for rescuing from all KahunaClient errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status = nil, data = nil) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kahuna_client/error.rb', line 8

def initialize(message, status=nil, data=nil)
  super(message)
  @status = status
  if data
    begin
      json_hash = MultiJson.load(data, symbolize_keys: true)
      @error_code = json_hash[:error_code] # should be the same as the HTTP status
      @error_message = json_hash[:error]
    rescue MultiJson::ParseError => exception
      # nothing to do
    end
  end
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



6
7
8
# File 'lib/kahuna_client/error.rb', line 6

def error_code
  @error_code
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



6
7
8
# File 'lib/kahuna_client/error.rb', line 6

def error_message
  @error_message
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/kahuna_client/error.rb', line 6

def status
  @status
end