Exception: KB::Error
- Inherits:
-
StandardError
- Object
- StandardError
- KB::Error
- Defined in:
- lib/kb/errors/error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#message ⇒ Object
Returns the value of attribute message.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status_code = nil, body = nil, error = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(status_code = nil, body = nil, error = nil) ⇒ Error
Returns a new instance of Error.
5 6 7 8 9 10 11 12 |
# File 'lib/kb/errors/error.rb', line 5 def initialize(status_code = nil, body = nil, error = nil) super(error) @status_code = status_code @body = body @message = "Received Status: #{status_code}\n#{body}" @message = error. if error.present? && body.nil? && status_code.nil? set_backtrace error.backtrace if error end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/kb/errors/error.rb', line 3 def body @body end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/kb/errors/error.rb', line 3 def @message end |
#status_code ⇒ Object
Returns the value of attribute status_code.
3 4 5 |
# File 'lib/kb/errors/error.rb', line 3 def status_code @status_code end |
Class Method Details
.from_faraday(error) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kb/errors/error.rb', line 14 def self.from_faraday(error) case error.response&.[](:status) when 404 ResourceNotFound when 409 ConflictError when 422 UnprocessableEntityError else self end.new(error.response&.[](:status), error.response&.[](:body), error) end |