Exception: RockingChair::Error
- Inherits:
-
StandardError
- Object
- StandardError
- RockingChair::Error
- Defined in:
- lib/rocking_chair/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code, error, reason) ⇒ Error
constructor
A new instance of Error.
- #message ⇒ Object
- #raise_rest_client_error ⇒ Object
- #to_json ⇒ Object
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/rocking_chair/error.rb', line 6 def code @code end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/rocking_chair/error.rb', line 6 def error @error end |
#reason ⇒ Object (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_404 ⇒ Object
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_409 ⇒ Object
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_500 ⇒ Object
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
#message ⇒ Object
14 15 16 |
# File 'lib/rocking_chair/error.rb', line 14 def "#{@code} - #{@error} - #{@reason}" end |
#raise_rest_client_error ⇒ Object
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_json ⇒ Object
18 19 20 |
# File 'lib/rocking_chair/error.rb', line 18 def to_json {"error" => @error, "reason" => @reason }.to_json end |