Exception: Smplkit::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Smplkit::Error
- Defined in:
- lib/smplkit/errors.rb
Overview
Base exception for all smplkit SDK errors.
Direct Known Subclasses
ConflictError, ConnectionError, NotFoundError, TimeoutError, ValidationError
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message = nil, errors: nil, status_code: nil) ⇒ Error
constructor
A new instance of Error.
- #to_s ⇒ Object
Constructor Details
#initialize(message = nil, errors: nil, status_code: nil) ⇒ Error
Returns a new instance of Error.
35 36 37 38 39 40 |
# File 'lib/smplkit/errors.rb', line 35 def initialize( = nil, errors: nil, status_code: nil) @errors = errors || [] @status_code = status_code ||= self.class.(@errors) super() end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
33 34 35 |
# File 'lib/smplkit/errors.rb', line 33 def errors @errors end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
33 34 35 |
# File 'lib/smplkit/errors.rb', line 33 def status_code @status_code end |
Class Method Details
.derive_message(errors) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/smplkit/errors.rb', line 55 def self.(errors) return "An API error occurred" if errors.nil? || errors.empty? first = errors[0] msg = first.detail || first.title || first.status || "An API error occurred" extra = errors.length - 1 msg += " (and 1 more error)" if extra == 1 msg += " (and #{extra} more errors)" if extra > 1 msg end |
Instance Method Details
#to_s ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/smplkit/errors.rb', line 42 def to_s base = super return base if @errors.empty? if @errors.length == 1 "#{base}\nError: #{@errors[0].to_json}" else lines = [base, "Errors:"] @errors.each_with_index { |err, i| lines << " [#{i}] #{err.to_json}" } lines.join("\n") end end |