Exception: RockingChair::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, error, reason) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
# File 'lib/rocking_chair/error.rb', line 8

def initialize(code, error, reason)
  @code = code
  @error = error
  @reason = reason
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#reasonObject (readonly)

Returns the value of attribute reason.



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

def reason
  @reason
end

Class Method Details

.raise_404Object



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

def self.raise_404
  raise RockingChair::Error.new(404, 'not_found', "missing")
end

.raise_409Object



37
38
39
# File 'lib/rocking_chair/error.rb', line 37

def self.raise_409
  raise RockingChair::Error.new(409, 'conflict', "Document update conflict.")
end

.raise_500Object



41
42
43
# File 'lib/rocking_chair/error.rb', line 41

def self.raise_500
  raise RockingChair::Error.new(500, 'invalid', "the document is invalid.")
end

Instance Method Details

#messageObject



14
15
16
# File 'lib/rocking_chair/error.rb', line 14

def message
  "#{@code} - #{@error} - #{@reason}"
end

#raise_rest_client_errorObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/rocking_chair/error.rb', line 22

def raise_rest_client_error
  case code
  when 404
    raise RestClient::ResourceNotFound
  when 409
    raise RestClient::Conflict
  else
    raise "Unknown error code: #{code.inspect}"
  end
end

#to_jsonObject



18
19
20
# File 'lib/rocking_chair/error.rb', line 18

def to_json
  {"error" => @error, "reason" => @reason }.to_json
end