Exception: Etcd::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/etcd/exceptions.rb

Overview

Represents all etcd custom errors

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
16
# File 'lib/etcd/exceptions.rb', line 11

def initialize(opts = {})
  super(opts['message'])
  @cause = opts['cause']
  @index = opts['index']
  @error_code = opts['errorCode']
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



9
10
11
# File 'lib/etcd/exceptions.rb', line 9

def cause
  @cause
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



9
10
11
# File 'lib/etcd/exceptions.rb', line 9

def error_code
  @error_code
end

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/etcd/exceptions.rb', line 9

def index
  @index
end

Class Method Details

.from_http_response(response) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/etcd/exceptions.rb', line 18

def self.from_http_response(response)
  opts = JSON.parse(response.body)
  unless ERROR_CODE_MAPPING.key?(opts['errorCode'])
    fail "Unknown error code: #{opts['errorCode']}"
  end
  ERROR_CODE_MAPPING[opts['errorCode']].new(opts)
end

Instance Method Details

#inspectObject



26
27
28
# File 'lib/etcd/exceptions.rb', line 26

def inspect
  "<#{self.class}: index:#{index}, code:#{error_code}, cause:'#{cause}'>"
end