Exception: SimpleSpark::Exceptions::Error
- Inherits:
-
StandardError
- Object
- StandardError
- SimpleSpark::Exceptions::Error
- Defined in:
- lib/simple_spark/exceptions.rb
Overview
Adding an object to the exception to pass errors back begin
raise Error.new({ id: '1' }), "a message"
rescue Error => e
puts e. # => "a message"
puts e.object # => { id: '1' }
end
Direct Known Subclasses
BadRequest, GatewayTimeoutExceeded, InvalidConfiguration, NotFound, ThrottleLimitExceeded, UnprocessableEntity
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object = nil, results = {}) ⇒ Error
constructor
A new instance of Error.
- #transmission_id ⇒ Object
Constructor Details
#initialize(object = nil, results = {}) ⇒ Error
Returns a new instance of Error.
13 14 15 16 |
# File 'lib/simple_spark/exceptions.rb', line 13 def initialize(object = nil, results = {}) @object = object @results = results end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
11 12 13 |
# File 'lib/simple_spark/exceptions.rb', line 11 def object @object end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
11 12 13 |
# File 'lib/simple_spark/exceptions.rb', line 11 def results @results end |
Class Method Details
.fail_with_exception_for_status(status, errors, results) ⇒ Object
22 23 24 25 |
# File 'lib/simple_spark/exceptions.rb', line 22 def self.fail_with_exception_for_status(status, errors, results) exception = status_codes[status.to_s] || status_codes['default'] fail exception.new(errors, results), errors.map { |e| "#{e['message']} #{status} (Error Code: #{e['code']})" + (e['description'] ? ": #{e['description']}" : '') }.join(', ') end |
.status_codes ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_spark/exceptions.rb', line 27 def self.status_codes { 'default' => Exceptions::UnprocessableEntity, '400' => Exceptions::BadRequest, '404' => Exceptions::NotFound, '422' => Exceptions::UnprocessableEntity, '420' => Exceptions::ThrottleLimitExceeded, '429' => Exceptions::ThrottleLimitExceeded } end |
Instance Method Details
#transmission_id ⇒ Object
18 19 20 |
# File 'lib/simple_spark/exceptions.rb', line 18 def transmission_id results['id'] end |